Tell me more ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

Coding standards are common in any software development organization, but how important are they to follow? I can understand the need for some consistency, but when dealing with simple things like the position of braces, line length, etc., I'm not sure excessively strict standards contribute much to software development.

Isn't it more important that your code is readable, not that it conforms to a predefined standard? It seems they're more like... guidelines anyway.

share|improve this question

6 Answers

up vote 4 down vote accepted

Asking everyone to 100% adhere to the same standard code formatting guideline is like asking everyone to collaborate separately on writing a 100 page paper with the same writing style.

Hopefully everyone will write the paper in English (or same language), but different styles will be apparent. Some will write it well, others not. Some will use contractions, some will spell the words out fully (example: it's verus it is). Etc.

I think you touched on the most important points:

  1. It's a guideline
  2. Readability

If you want the code to adhere to the same formatting, like a paper to be in the same writing style, it'll need editing and revising. The code will need to be cleaned up, reviewed, re-factored, etc.

I've never been in a shop where I was completely happy with another developer's coding style or formatting (at minimal because it's not exactly like mine). But I'll be content if I can read/understand it and if it's consistent. Everything else is the sugar on the syntactic sugar.

So to answer your question: somewhat important, but it's certainly not the end of the world if they don't.

share|improve this answer
Especially #2: Readability. Sometimes a specific bit of code can be made more readable by deviating from the guideline. – Bart van Heukelom Sep 14 '10 at 10:01

Guidelines help improve quality of code:

  • from the writer point of view: many rules aim at reducing the introduction of bugs. For instance, a rule stating that if() or for(;;) constructs must be followed by a block and not a single instruction, makes intention of initial coder explicit and helps next coders maintain this.

  • from the reader point of view: code that follows agreed guidelines is reviewed more efficiently than code with various styles. The reviewer knows better with less effort where to look for possible bugs.

share|improve this answer

The worst thing I've encountered so far is using no coding standards. And you are prohibited to make some code block more readable because it breaks diff tools... Because we are using patches to apply changes (change/bug fix request -> fix/change -> patch -> patch applied by "trusted" person -> commit) you can get pretty funny looking source code (from readability point of view). At least we do not have anyone using two letter variables (-.

[rant] The funniest thing is that everyone agrees that we need to change this. There were even a couple of reformat attempts (automated on commit), but because a single tiny itsy bitsy formatting option is missing - the all thing just got through out. Sight... [/rant]

share|improve this answer

If you use and IDE that does the basics of this for you (Visual Studio for example), let the IDE do it's thing and whatever seems to still be hard to look at you modify as long as you still let the IDE do it's thing or the next person that auto-formats it is just going to kill it anyway.

What is most readable to one person will not be for all people.

If you are not using this sort of IDE get one. Even thinking about this for more than 10 minutes is a waste of resources IMHO.

share|improve this answer
2  
I have to disagree. I find nothing more irritating than an IDE that changes the formatting on its own. Why should I be letting it modify my code without my consent? It cuts out a decent portion of control that I like to have over my work. – derekerdmann Sep 11 '10 at 4:45
Bill, are you talking about the drag-n-drop naming conventions that the IDE generates such as TextBox01? Or do you mean a Visual Studio plugin like Resharper? – sunpech Sep 11 '10 at 18:24
derek - yes, that is annoying, but the time it saves me from not having to pay attention to it 90% of the time is worth the 10% of the time I have to wrestle it. – Bill Sep 11 '10 at 18:57
sun - I meant formatting only in this case. I would be ok with the default control names on drop only if it were exceedingly obvious what was going on. in many forms that falls apart after the second control. I am not a huge resharper fan, but when I use it I don't try and correct what it generates much either. Don't fight your toolset when you don't have to. – Bill Sep 11 '10 at 19:01
There can be multiple IDEs in the same team - E.g. Eclipse and IDEA for Java. It would take a little effort to setup code formatting in the form of config files - but it's worth it. – talonx Sep 14 '10 at 11:17

At my current job, one of my first tasks was to come up with a coding standard for our development group.

My first effort was about sixty pages long (it incorporated much of the Framework Guidelines from Microsoft). I was asked to pare it down, and my next effort was ten pages long, utilizing ideas from a variety of good sources. I was asked to pare it down again, and finally got it down to three or four pages, I think.

It was never adopted.

Why? Because I work with a lot of really smart people, who already follow a sensible coding standard instinctively.

For my part, I follow generally-accepted guidelines from Microsoft, and emulate the commonly-used styles of others (Javascript and jQuery are formatted differently from C#, even though they are both curly-brace languages). I also break the rules from time to time, when doing so will make the code more readable.

share|improve this answer

For formatting standards, I follow what everybody else is doing. If they are using PascalCase for everything, then I use PascalCase. If they use _camelCase, then I use _camelCase. Why? Because it limits the amount of reformatting I do, and limits what others have to do to make it "look good". Formatting standards are usually there to make things easy for everybody.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.