Over the years I have developed several style based techniques which I use to keep my from make Error if(const == lvalue) rather then if(lvalue == const) since the first can't fall victim to the classic accidental assignment goof.

I recently worked on a project with very unusual style standards and I found that I had much greater difficulty reading code. Has anyone seen any statistics on a particular coding style and its defect levels or have any experience with changing style alone to improve defect rates.

  • 11
    If your compiler isn't warning you when you accidentally write assignment instead of equality, I submit that your compiler is broken. :)
    – greyfade
    Nov 18, 2010 at 16:29
  • 1
    +1: For the idea that poor coding style can lead to defects (because it certainly can).
    – Jim G.
    Nov 18, 2010 at 17:08
  • 6
    enable all the warnings you can, and then make the compiler happy. It WILL save you from a 3 AM call.
    – user1249
    Nov 18, 2010 at 17:27
  • @greyfade: or your editor. emacs can warn for assignments in if/while in real-time.
    – Gauthier
    Mar 29, 2011 at 7:37

2 Answers 2


If you haven't read it yet, you should definitely take a look at Code Complete, 2nd Edition by Steve McConnell. Almost the entire book is devoted to this type of discussion along with actual studies to back up his ideas.


In general, the most significant characteristics of a coding style are that the company has one, and that it is followed consistently by everyone. The actual details of that coding style are of secondary importance, provided the coding style is a reasonably good one.

The (const == lvalue) trick has been largely superseded by the fact that compilers and IDE's are now available that can generate a suitable warning.

  • 1
    That trick is still enshrined in standards in some places where the attitude is "we don't expect developers to read all of the compiler warnings."
    – Cascabel
    Nov 18, 2010 at 16:32
  • 1
    People who say that generally can't write tight, error free code. It is extremely rare that more that 5-10 sec are needed to resolve a warning, esp. this one.
    – Michael K
    Nov 18, 2010 at 18:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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