Differences in the “standard” coding style from language to language frustrate me. I get irritated that I have to change styles to fit in with the accepted norms for different languages.
Traditionally, some use variable names with_underscores, some MixedCase some mixedCase with the first word uncapitalized, some use tabs, some use spaces, etc.
I can code semi-fluently in six or seven languages, and I get tired of having to remember what the accepted style is for particular language I’m in. So, at the risk of looking like a complete boob, I hereby declare my independence from other people’s coding styles. Specifically:
(Of course, I can do this because I am master of my own programming universe. Let me throw in this disclaimer: if my company goes belly up one day, and you interview me for a job, and then you come read this post — rest assured I will comply with whatever standard your great and benevolent organization wants me to, kind sir.)
I had a Skype conversation with Adam Kalsey about this a few weeks ago. He did bring up the point that MixedCase PHP can be hard to do in vi because the first letter gets lost against the dollar sign. While I respect his point, I don’t see it as a huge issue.
Ken Arnold talked about this in an essay in Spolsky’s “The Best Software Writing.” He said this:
For almost any mature language (C, Java, C++, Python, Lisp, Ada, FORTRAN, Python, Smalltalk, sh, javascript, …) coding style is an essentially solved problem, and we ought to stop worrying about it. And to stop worrying about it will require worrying about it a lot first, because the only way to get from where we are to a place where we stop worrying about style is to enforce it as part of the language.
I agree. Enforce coding styles at the compiler level. Your brackets are in the wrong place? App doesn’t compile. You used an underscore in a variable name? App doesn’t compile. The specifics of the style doesn’t so much matter, just that the style is enforced, everyone has to use it, and we can all stop arguing about the best way to do it.
I feel the same way about this as I do about school uniforms. My kids aren’t in school to look fashionable. They’re there to learn, so make all the kids dress the same so we can remove that distraction completely. Same goes with coding: we don’t write code to use our own coding conventions, so let’s make everyone do it the same so we can remove that distraction complete.y
There’s precedent here, of course:
There’s a lot to be said for this, there really is. We waste too much time arguing about it, and there are too many problems when someone comes in and uses a wildly differing style on an existing codebase.
Thank you, thank you, thank you. Couldn't have said it better.
Although I still like Perl's coding style: Do whatever the heck you want to do!
In Ruby, constants are ALL_CAPS
by convention - constants just need to start with an uppercase. class and module names are constants, but differ greatly from other constants, and so the ALL_CAPS convention has arisen.
i like the idea that convention be enforced by a (pre?) compiler. it shouldn't be that hard to write a couple of regular expressions to enforce a coding style, no?
I've always been more of a mixedCaps sort of guy myself.
One thing that always irked me was when people would start brackets on the same line as an IF statement...
IF (a !=b) {
cout << "test";
}
...for example. I have this compelling drive to always place associated brackets on the same indent level. I understand the logic behind the above usage (the bracket almost acts as the "THEN" statement), but it just looks funny to me. I worked with someone for an entire semester project with whom I agreed on nearly every formatting convention except that one, and it was always an unspoken battle that we'd revise each other's formatting to make it consistent.
I have this compelling drive to always place associated brackets on the same indent level.
Yes, exactly. Exactly, exactly, exactly.