Take the 2-minute tour ×
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.

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.

share|improve this question
8  
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 '10 at 16:29
1  
+1: For the idea that poor coding style can lead to defects (because it certainly can). –  Jim G. Nov 18 '10 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 '10 at 17:27
    
@greyfade: or your editor. emacs can warn for assignments in if/while in real-time. –  Gauthier Mar 29 '11 at 7:37

2 Answers 2

up vote 7 down vote accepted

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.

share|improve this answer

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.

share|improve this answer
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." –  Jefromi Nov 18 '10 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 '10 at 18:43

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.