Correct Coding Style

There is a correct way to write code in C++ (and any other lang but it’s different for each) and their is a wrong way. Both produce programs that work – and may work as fast. The correct way creates code that is easy to read – the wrong way creates code I refuse to read. For anyone that cared – this is what I say the right way is…

Spaces, spaces, spaces! - Place spaces before and after every operator!

Right:

if (foo == bar)

moosecow = hotshit + ass;

Wrong:

if (foo==bar)

moosecow=hotshit+ass;

Call in support we have Brackets! – Never place brackets on the same line as if/class definition!

Right:

If (moosecow == hey)

{

ADD CODE HERE

}

Wrong:

if (moosecow == hey) {

ADD CODE HERE

}

Those are the major ones; I agree almost 100% with this site (google cache).

Leave a Comment


NOTE - You can use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>