[RESOLVED] Coding standards (rules)
Hello guys!
If it's alright, I was wondering if some of you could share with me the policy on the conding standards of the company you guys work for. Example would be...
1. Use typedef for all data types
2. Use the following block style[code]void foo() {
...
}
3. Capitalize the first letter of a function
4. No Hungarian notation
5. And so forth...
I've read the general coding standards
but I'm far more interested in hearing from all the working professionals here,
so that in the future when I get a job, I'd be better prepared.
As always, thanks!
Re: Coding standards (rules)
Here's a pretty good one. It covers a lot of things, so it's easy to compare it to your own style.
Re: Coding standards (rules)
Have you read C++ Coding Standards by Sutter and Alexandrescu? There is alot more to be considered than just stylistic guidelines.
Re: Coding standards (rules)
My company doesn't have a single monolithic set of coding standards, but there are guidelines within some specific projects.
Personally when I'm working with existing code I just follow the extant style, and when I'm writing my own I impose my preferred style. Really not a fan of your #2 incidentally.
Re: Coding standards (rules)
IMPO, Braces should be on their own line 99.5% of the time. The other 0.5% it may be acceptable to put the entire "construct" on one line:
Code:
void foo() { return 1; }
This is typical when there are many of the same time sequentially in the file...
Re: Coding standards (rules)
Quote:
Originally Posted by
potatoCode
2. Use the following block style[code]void foo() {
...
}
As always, thanks!
Words cannot describe how annoying I find that style of brace use.
Code:
void foo()
{
//code
}
is so much easier to see.
I use hungarian notation frequently.
I'd add that white space is important
Don't write multiple statements on a single line
Don't include superflous comments
Use meaningful variable and function names
Re: Coding standards (rules)
The most important thing is: Think through every function you add to an interface completely. If knowing how to use it requires any understanding of the internal implementation, you're doing it wrong.
Re: Coding standards (rules)
Quote:
Originally Posted by
GCDEF
I use hungarian notation frequently.
This is one I find very interesting. Consider how many class names there are and the FLA's (First Letter Acronyms) and other abbreviations regulrly clash.
For example what your use you for variables of the following types:
Code:
std::vector<int>
std::vector<double>
std::vector<vector<double>
std::vector<std::pair<int,double>>
std::vector<std::pair<doublie,int>>
I would find svspidData and svspdiData to be very confusing to refer to the last two types...
Re: Coding standards (rules)
Quote:
Originally Posted by TheCPUWizard
For example what your use you for variables of the following types:
I think that it depends on which variant of Hungarian notation is used. Joel Spolsky points out in Making Wrong Code Look Wrong that Simonyi's original Hungarian notation concept was concerned with the semantics of the variables, not their types as declared in the program. I tend to be more sympathetic towards this "Apps Hungarian", although I still do not understand why such an encoding is really necessary when spelling out the word would be easier to read for those uninitiated to the abbreviations.
Re: Coding standards (rules)
Quote:
Originally Posted by
GCDEF
I use hungarian notation frequently.
Yuck! :sick:
Why?? :confused:
I know in some cases its forced on us if you program in MFC or win32 :mad: but even then I'd only use it the absolute minimum you can get away with.
Re: Coding standards (rules)
Quote:
Originally Posted by
laserlight
I think that it depends on which variant of Hungarian notation is used. Joel Spolsky points out in
Making Wrong Code Look Wrong that Simonyi's original Hungarian notation concept was concerned with the semantics of the variables, not their types as declared in the program. I tend to be more sympathetic towards this "Apps Hungarian", although I still do not understand why such an encoding is really necessary when spelling out the word would be easier to read for those uninitiated to the abbreviations.
Even semantic usage gets a bit complex to say the least...
I find that the vast majority of the time simply hacing the class name in ProperCase a local variable with the exact same name in camelCase is sufficient.
For "Collection" classes, I tent to end with the Collection Type (CarList, StateMap, etc) variables can then simple be plural)
(psuedo code)
Code:
CarList cars;
foreach (Car car in cars)
{
}
Re: Coding standards (rules)
Quote:
Originally Posted by
Russco
Yuck! :sick:
Why?? :confused:
I know in some cases its forced on us if you program in MFC or win32 :mad: but even then I'd only use it the absolute minimum you can get away with.
Habit I guess. Mainly just for PODs.
Re: Coding standards (rules)
Quote:
Originally Posted by
TheCPUWizard
IMPO, Braces should be on their own line 99.5% of the time.
Quote:
Originally Posted by
GCDEF
Code:
void foo()
{
//code
}
So you also write
Code:
if (a==b)
{
foo();
}
else
{
bar();
}
?
And you find that easy to read?
Re: Coding standards (rules)
Personally I usually omit braces entirely when it's a single-line statement. Either that or use ? notation.
Re: Coding standards (rules)
Take a look at this. Evidently, Bjarne helped develop some coding standards.
http://www.research.att.com/~bs/bs_faq2.html
I used to use hungarian notation a bit. It is flexible. I like the idea of including scope into variable names to avoid confusion between locals and members. Globals should be within a namespace at the very least which helps to clarify when using the '::' operator to indicate where the variable is located. It gets a bit ridiculous when you try to include type info into the variable name.