Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do you have coding standards? If so, how are they enforced? [closed]

Tags:

I've worked on a couple of projects where we spent a great deal of time discussing and writing elaborate coding standards covering everything from syntax layout to actual best practices. However, I have also found that these are rarely followed to the full extent. Many developers seem to hesitate to reject a code review based on coding standard violations alone. I.e. violations are committed to the repository on a regular basis.

My questions are: Do you have coding standards? What do they cover? Are they followed by everyone? And what do you do (if anything) to make sure everybody is following the standards?

I'm aware that there is a similar question here, but my concern is not so much how you could do it, but how you are actually going about it and what are the perceived benefits?

like image 446
Brian Rasmussen Avatar asked Dec 18 '08 08:12

Brian Rasmussen


2 Answers

I've worked in places with barely-followed coding practices, and others where they're close to being enforced - or at least easily checked.

A few suggestions:

  • The most important thing is to get buy-in to the idea that consistency trumps your personal preferred style. There should be discussion of the coding standard both before and after it's instituted, but no-one should be allowed to just opt out of it.
  • Code reviews should be mandatory, with the checkin comment including the username of the reviewer. If you're using a suitably powerful SCM, consider not allowing checkins which don't have a valid reviewer name.
  • There should be a document which everyone knows about laying out the coding standards. With enough detail, you shouldn't get too much in the way of arguments.
  • Where possible, automate checking of the conventions (via Lint, CheckStyle, FXCop etc) so it's easy for both the committer and the reviewer to get a quick check of things like ordering import/using directives, whitespace etc.

The benefits are:

  • Primarily consistency - if you make it so that anyone can feel "at home" in any part of the codebase at any time, it gives you more flexibility.
  • Spreading best practice - if you ban public fields, mutable structs etc then no-one can accidentally plant a time bomb in your code. (At least, not a time bomb that's covered by the standard. There's no coding standard for perfect code, of course :)

EDIT: I should point out that coding standards are probably most important when working in large companies. I believe they help even in small companies, but there's probably less need of process around the standard at that point. It helps when all the developers know each other personally and are all co-located.

like image 109
Jon Skeet Avatar answered Sep 19 '22 14:09

Jon Skeet


Do you have coding standards?

Yes, differs from project to project.

What does it cover?

Code(class, variable, method, constant), SQL naming and formatting convention

Is it being followed by everyone?

Yes, every new entrant in project could be asked to create a demo project following organization coding convention then it gets reviewed. This exercise makes developer feel at ease before starting real job.

And what do you do (if anything) to make sure everybody is following the standard?

Use StyleCop and FxCop to ensure they are religiously followed. It would show up as warning/error if code fails to comply with organization coding convention.

Visual Studio Team system has nice code anlysis and check-In policies which would prevent developers checking in code that does not comply

Hope, it helps

Thanks, Maulik Modi

like image 23
msqr Avatar answered Sep 20 '22 14:09

msqr