|
Yes, writing code is an art. Yet the art is not in its presentation, but rather its meaning. Because of this, code style conformity is a virtue. When one reads two novels by two different authors, one doesn’t expect there to be differences in the layout of sentences on the page, nor differences in characters used to express inherent meaning. Rather, it is through conformity that one is freer to appreciate the writing. Indeed nonconformity in coding style detracts from its meaning, and obscures interpretation.
When I code in Java, I use Sun's guidelines[^]. When I code in C#, I use Microsoft's[^]. Microsoft spent a lot of energy coming up with their guidelines and made some good choices.
I wonder how many C# developers are aware of the Microsoft guidelines, and who have read and follow the conventions therein. I know there are many that do not. Curiously, from my own observations, the proportion of Java developers that adhere to Sun’s guidelines appears to be greater than the proportion of C# developers that adhere to Microsoft’s. One may speculate on the reason for this disparity.
Code conventions are important in team environments.
I find it a hindrance reading C# code with Hungarian notation or fields prefixed with ‘_‘ or ‘m_’; or needless use of ‘this’. This is because such styles are not what I’m used to. When I first started using C#, I adopted the use of a prefix ‘_’ for member variables. Fortunately after a couple of weeks I stopped this practice when I realised it was unnecessary, and that it violated the MS guidelines. I now know that when practices, such as those mentioned above, become necessary it is indicative of poor design.
Indeed code style is a contentious issue. My advice though is to follow the language vendor’s guidelines because it saves a new developer from having to learn your organisations custom style conventions, and expedites collaboration with others outside of your organisation.
Microsoft Design Guidelines for Class Library Developers[^]
Sun Code Conventions for the Java Programming Language[^]
Daniel Vaughan
Zen Diaphragm
|
|
|
|
|
I can't say it surprises me any more, but developers are spending way too much energy on less important aspects of coding standards/guidelines, like naming conventions. It is not that important whether to prefix a member variable with m_ . A much more important thing is to design your types correctly, to write exception-safe code, to document your work properly, to have code reviews...
Definitely the best book on coding standards[^] (C++ specific) I am aware of does not even mention things like naming conventions and placement of curly braces.
My programming blahblahblah blog. If you ever find anything useful here, please let me know to remove it.
-- modified at 10:22 Tuesday 30th August, 2005
|
|
|
|
|
If your message isn't worth a 5, I don't know what is. Amen!
Good music: In my rosary[^]
|
|
|
|
|
They say Programming is an 'art' why do they then ask us to follow these conventions... ?? Should'nt an artist (programmer) have free hand?
|
|
|
|
|
Depends - do you want to get paid for your art?
|
|
|
|
|
|
Ali I. wrote:
They say Programming is an 'art' why do they then ask us to follow these conventions... ?? Should'nt an artist (programmer) have free hand?
The main reason is that it's usually a group effort. If you always work alone, then it won't matter what conventions (if any) you follow. But in a group, it makes a difference.
Alvaro
Explain to the mothers & fathers of American servicemen that may come home in body bags why their son or daughter have to give up their life?" -- Sean Hannity, 1999.
|
|
|
|
|
End of the day... you are not the owner or the 'gate keeper' for the art. Sor, make the art understandable to the next person too - so follow some guidelines
"He that is good with a hammer tends to think everything is a nail." - Abraham Maslow
|
|
|
|
|
S P S wrote:
End of the day... you are not the owner or the 'gate keeper' for the art.
Depends on where you work and what your job function is. Since I am the only windows programmer in my department I am the only person responsible for the 500K+ lines of MFC code that I have written in my current job (since early 1997).
John
|
|
|
|
|
OK, exceptions ruled out
"He that is good with a hammer tends to think everything is a nail." - Abraham Maslow
|
|
|
|
|
Yep, a couple years ago when we were a real software development team, we came up with a pretty good coding standard. The funny part was reaching the consensus. All important points (use of smart pointers, STL, standard strings, documentation, ...) we resolved quickly and unanomously, and then lost weeks arguing where to put curly braces
My programming blahblahblah blog. If you ever find anything useful here, please let me know to remove it.
|
|
|
|
|
On a new line, right? :P
regards,
Paul Watson
South Africa
Colib and WebTwoZero.
K(arl) wrote:
oh, and BTW, CHRISTIAN ISN'T A PARADOX, HE IS A TASMANIAN!
|
|
|
|
|
K & R brace style, like God intended.
Software Zen: delete this;
|
|
|
|
|
Hi coders..
What code casing style do you follow? you know we have number of them, e.g.,
camelCasing,
PascalCasing,
Finger_Breaking_Underscore,
DataTypeVariable etc.
To start the debate, I start with my experience. We use camelCasing most.
Not everything that can be counted counts and not everything that counts can be counted - Einstein
-- modified at 5:25 Monday 29th August, 2005
|
|
|
|
|
We prefer PascalCasing and think camelCasing is pretty horrible. However, we do use camelCasing for variable names, in line with .NET style recommendations. We do so by using a small set of well-defined prefixes, such as "my" to identify member variables. The lower case part of the camelCase will always be one of these informative prefixes.
Gavin Greig
"Haw, you're no deid," girned Charon. "Get aff ma boat or ah'll report ye."
Matthew Fitt - The Hoose O Haivers: The Twelve Trauchles O Heracles.
|
|
|
|
|
myDocuments.
ARGH!
(Apologies for this post not being constructive.)
regards,
Paul Watson
South Africa
Colib and WebTwoZero.
K(arl) wrote:
oh, and BTW, CHRISTIAN ISN'T A PARADOX, HE IS A TASMANIAN!
|
|
|
|
|
Yeah, we did swither a bit about it, but we went for it in the end. It may be associated with "My Documents" and also - perhaps more seriously - the forthcoming "My" namespace, but in the end it was a real word, it was short, and it indicates that the variable "belongs" to something (a class).
Gavin Greig
"Haw, you're no deid," girned Charon. "Get aff ma boat or ah'll report ye."
Matthew Fitt - The Hoose O Haivers: The Twelve Trauchles O Heracles.
|
|
|
|
|
Oh for sure, I think it is perfectly fine. I just know the VB and Fisher Windows haters out there will deride it for being like me and My Documents.
regards,
Paul Watson
South Africa
Colib and WebTwoZero.
K(arl) wrote:
oh, and BTW, CHRISTIAN ISN'T A PARADOX, HE IS A TASMANIAN!
|
|
|
|
|
I use camelCase for variable and method names, and PascalCase for class names. I don't prefix class names with C and do prefix interfaces with I . I also use Hungarian notation, and prefix data members with m_ .
<aside>
Tabs replaced with spaces
Indentation = K&R
Comments = Doxygen
</aside>
/ravi
My new year's resolution: 2048 x 1536
Home | Music | Articles | Freeware | Trips
ravib(at)ravib(dot)com
|
|
|
|
|
this question has already been subject to a survey here[^]...
but i still use camelCase...
TOXCCT >>> GEII power [toxcct][VisualCalc]
-- modified at 8:09 Monday 29th August, 2005
|
|
|
|
|
It still blows my mind in these days of OO and strongly typed languages that people prefix variable instances with the details of the implementation.
It's so anti data hiding.
Dale Thompson
|
|
|
|
|
Dale Thompson wrote:
It's so anti data hiding.
Doesn't data hiding include hiding the actual variables?
Behind every great black man...
... is the police. - Conspiracy brother
Blog[^]
-- modified at 10:00 Monday 29th August, 2005
|
|
|
|
|
We use camelCasing for local Variables, m_camelCasing for Members.
Function names are in PascalCasing, and statics and globals are rare
(Well - the theory says that they are PascalCasing).
MACROS and DEFINEs are Capitals.
"We trained hard, but it seemed that every time we were beginning to form up into teams we would be reorganised. I was to learn later in life that we tend to meet any new situation by reorganising: and a wonderful method it can be for creating the illusion of progress, while producing confusion, inefficiency and demoralisation."
-- Caius Petronius, Roman Consul, 66 A.D.
|
|
|
|
|
I mostly use PascalCasing for function names and extended version of the hungarian notation for all the other things.
Behind every great black man...
... is the police. - Conspiracy brother
Blog[^]
|
|
|
|
|
I use PascalCasing for classes, methods, and class members and camelCasing for local variables in methods.
|
|
|
|