I am a huge fan of .NET Framework 1.1 Naming Guidelines available here.
Also I prefer to code using hungarian notation from Charles Simonyi.
What about you? Which naming guidelines do you follow in which programming language?
|
I am a huge fan of .NET Framework 1.1 Naming Guidelines available here. What about you? Which naming guidelines do you follow in which programming language? |
|||||
|
|
You should follow the lexical conventions of the file, subsystem, project, and language you're working in, in roughly that order of precedence. This will include things like the use of CamelCase versus underscores, conventional use of prefixes/suffixes, Hungarian notation (either Simonyi's original intent or the broken Systems Hungarian or neither), and so on and so on. Once you're past the above (and that's what most people argue about), naming guidelines really boil down to effective communication: how do you make your code readable. Here are some thoughts that I have come to believe over the years.
One suggestion that is often in tension with those above, and yet I also believe is quite important: Don't be (too) verbose. Good notation is concise notation, and names are a form of notation.
I suspect that this last set of thoughts is where I most differ from current conventional wisdom. Finally, I would highly recommend reading Clean Code by Robert C. Martin. It's probably the best book I've ever read on the general issues of code and design tidiness (including naming conventions) at the level of the function, file, and subsystem. |
|||||||||||
|
|
There needs to be a clear distinction between Hungarian notation as originally intended by Charles Simonyi and Systems Hungarian. Thanks to @Inaimathi for pointing to this article joelonsoftware.com/articles/Wrong.html. I admit that I was one of those who fell victim to this misunderstanding. I don't think Systems Hungarian notation adds much value nowadays, when embedding data-type information in variable names. Linus Torvalds and Bjarne Stroustrup said it best: Linus Torvalds:
Bjarne Stroustrup:
I can see Hungarian notation being very valuable in UI programming where it is benefitial to know whether somethign is a text field or a label. For example, I usually do this: lblCustomerName (label preceding the text field), txtCustomerName (actual text field). Also, whatever convention you chose, make sure the name is descriptive and does not need a comment line above variable declaration. It doesn't cost us anything to make a descriptive variable, method, or class name. In the end, the code will be more readable, which is important. Programmers spend more time reading code than writing it. On a more technical side of things, below are some of the guidelines that I follow, which use Hungarian notation (I'm a .NET developer):
|
|||||||||||||
|
|
In Elisp/Scheme/Common Lisp, I follow the naming conventions implicitly set out in Practical Common Lisp with a few changes, influenced by PLT Racket coding standards. All lower case, sub-words delimited by For example (these aren't necessarily GOOD function names, I'm just using them to demonstrate the above standards)
These are all composeable, of course, so I could name a function In other languages (which tend not to use prefix notation), I just stick to the standard camel-caps naming, but I do name any predicate functions with a trailing |
||||
|
|
|
Following the style of the standard library for that language leads to nice-looking code. If you're in a language that does object.SomeMethod() or object.someMethod() or object.some_method() in its standard library and you follow that convention it will at least look professional. Ultimately they're just identifiers that some compiled languages throw away anyway, so don't spend too much time deciding among someMethod, SomeMethod or some_method. |
|||
|
|
|
First: use whatever case convention is generally accepted for the language of choice, and Second: the really important one, name classes, attributes and methods so you don´t need to write comments explaining them. |
|||
|
|
|
A better question would be, what popular languages don't have clear style guides from authoritative sources? I checked the google and found guides for Java, C#, ruby, python, php and c/c++ in less than a minute. Within php, there are pear and drupal guidelines. I'm convinced that much of the debate on coding styles is about the desire of some programmers to have some say on what their teammates do. |
|||
|
|
I use whatever ReSharper tells me to. |
|||||
|
|
I tend to think people over complicate naming conventions. My rule is simple. A variables name should convey the data it stores with emphasis on human readability. That is my only rule and it has served me well over the years. |
|||
|
|
|
I follow whatever naming guidelines are published (or accepted) for the language I'm using: In C# I use In Java or PHP I would use In Ruby or Python I would use |
|||
|
|
|
I work in C# and use CodeAnalysis (FxCop) and SourceAnalysis (StyleCop) to provide guidance for naming styles. |
|||
|
|
|
I think that Code Complete is a very good general book in naming stuff. It is also important that you take into consideration what language you are using. |
|||
|