PDA

View Full Version : 2 Cents about good programming practices in C/C++


DX-MON
06-16-2008, 09:33 AM
I desided to make a thread on what are the best programming practices to use in C/C++, please comment on what you feel about these to useful and powerful languages, my initial list follows.....


Don't use a compressed format (no if (a == b) {
statements;
})
if you have to use brackets, use the form if (a == b)
{
statements;
}
as from that it's always clear as to what each braket belongs to.
Always comment upon the code, not just for others sakes, but for yours in the future
Whenever you have to do complex things, split it up into separate functions
NEVER with hold on using switch/select statements
If you're thinking that you've not got enough checking happening in your code, you don't.... never think that lots of if statemnts are bad, they aren't.
too many functions are bad, you're probably repeating something, or not optimizing it properly.


If you do the above in C/C++ then you will get good, optimized code out of any compiler, and it'll always be easy to debug.