This repository has been archived by the owner on Aug 18, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 33
Code Guidelines
jbarnette edited this page Sep 12, 2010
·
10 revisions
Guidelines aren’t laws. What’s important is consistency. Anybody’s welcome to change these, just get consensus and make sure all the existing code matches your new guideline.
// bad
if (something)
do_something();
// good
if (something)
do_something();
// bad
if (something) {
do_something();
}
// good
if (something)
{
do_something();
}
// bad
if ( (foo && bar ) || baz )
do_something();
// good
if ((foo && bar) || baz)
do_something();
// bad
Type * variable;
Type *variable;
// good
Type* variable;
// bad
bool do_something() {
if (flag_p()) do_something_else();
switch(type_of_thingy()){
case FOO: handle_foo(); break;
case BAR: handle_bar(); return false;
default: handle_default();
}
if (flag_p()) do_something_else_again();
return true;
}
// good
bool do_something()
{
if (flag_p())
do_something_else();
switch (type_of_thingy())
{
case FOO:
handle_foo();
break;
case BAR:
handle_bar();
return false;
default:
handle_default();
}
if (flag_p())
do_something_else_again();
return true;
}