Mr. Pig’s House of Bacon

February 13, 2007

Correct Coding Style

Filed under: My Programs — Mr. Pig @ 10:13 pm

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 Reply