Registered: Oct, 2012
Re: Style is Substance
Posted: Oct 28, 2012 11:38 AM
I, Irchans, know of a programming style whose impact on programmer productivity and/or program quality is >= 5% when compared to any major common style. That style is "see below" and its benefits are faster coding and better thinking about code.
Well, I don't really have any evidence so this is just opinion and I'm sure you have seen these ideas before, but I think this style improves productivity by over 5% for C++.
1) At least 98% of your functions should be less than 40 lines of code. (I chose 40, but maybe 30 or 50 would be better.) I find it amazing how many programmers will write
for (i=0, i<iMax, i++)
// 300 lines of code
2) Put assertion at the front of most functions if your language does not support restricted range subtypes (as in Ada). If it supports subtypes, use them.
3) Use Lint.
4) Any function of over 20 lines of code deserves a comment.
5) If your variable is known to have specific physical units (like cm, feet, miles, watts, square meters), put the units in the variable name.
6) Use light Hungarian Notation (http://en.wikipedia.org/wiki/Hungarian_notation). (i.e. prefix integer types with an i, strings with an s, ...) I suggest that you don't use more complicated Hungarian Notation.
7) Program in a strongly typed language (like Haskell or Ada) if you can.