I spent most of the '90s as a consultant, learning new coding styles every 3-6 months. Most of them, like Where To Put The Braces (tm) are easy enough to adjust to. Want/don't want whitespace here and there? Fine. But certain things just burn my butt.
1) Never use do..while loops. Bzzzt. do..while loops have their place, and any decent editor makes it easy to find the closing brace to get what the end condition is. Your example is too simplistic to be realistic. A better one would be:
This is a maintenance nightmare. Sure, you could prolly put 'several lines of code' into it's own method, but oftentimes that's even less clear. Don't say "just set notDone to false and use a while loop", because you don't know what the done condition is, and IMHO adding phony booleans like notDone just to avoid a do..while loop is less clear.
2) Do not compound increment or decrement operators. Why not? These are basic and commonly used idioms, if you don't understand exactly what "foo(i++):" or "foo(--i);" do then I honestly don't want you mucking around in my code. I can guarantee you that if you don't grok foo(i++) then that will be the least of your problems. Same for the example of (y += 100 * y++). I can sorta see the reasoning behind this one (note the coding style uses x++, which is simpler). But IMHO this is again a common idiom that any programmer should understand.
2b) What's the problem with allowing i++ but not ++i? It depends on the algorithm. It's like saying you can only use a flathead screwdriver, never a phillips. Reasoning being you can use a flathead on a phillips screw.
I never saw the prohibitions above in any coding standard before. The one I always saw prohibited the ternary operator ('?'), usually because "it's too hard for beginners to understand". You're going to work on my 10 file, 3000 line program and you can't figure out how '?' works?
I agree 110% Hungarian Notation is Evil And Must Die. My favorite example is:
/ spent way too much of my life in meetings hammering out coding standards
// usually arguing against one thing or another
/// Actually had 1 phb that insisted on no extra parens, rational being "it slows down the compiler". This was 2001 or so.
//// Not bad, only 3 nits with your coding standard
Being cremated is my last chance at having a smoking hot body.
I always love these type of discussions! In my experience people are often more passionate about the code style guidelines than the actual code itself. Please do carry on!
Now where did I leave my popcorn.
Most of us disagree with those parts of the style guide. They are only suggestions. The really importantBitsWhichGetOverlookedAreTheBitsAboutSeparatingTokensWithSpaces. And line lengths.
And tabs vs spaces. Was a tab lover until I wrote a voice mail system in Python, now I'm like a reformed smoker
Do text editors that handle indentation for you, such as JEdit, use spaces or tabs? Probably depends on the settings of the individual editor. Guess I need to do some testing.
There are worse crimes than burning books. One of them is not reading them. Ray Bradbury
Joined: Oct 13, 2005
Robert D. Smith wrote: . . .
Do text editors . . . use spaces or tabs? Probably depends on the settings of the individual editor. . . .
I usually use gedit, where there is an option to convert tabs to spaces. I think they usually have that as an preference which you have to select. It may differ if you paste code which already has tabs in.