Skip to content

Instantly share code, notes, and snippets.

@ryanmr
Last active December 17, 2015 05:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryanmr/5561235 to your computer and use it in GitHub Desktop.
Save ryanmr/5561235 to your computer and use it in GitHub Desktop.
which do you like better? else if on the same bracket line or on their own new line?
void ABStar::Final() {
platform->enter_state();
if ( platform->get_nextChar() == 'a' ) {
platform->set_outputBuffer("In Final, found A");
platform->next_state();
NeedB();
} else if ( platform->get_nextChar() != '\0' ) {
platform->set_outputBuffer("In Final, found something other than B");
platform->next_state();
Error();
} else if ( platform->get_nextChar() == '\0' ) {
platform->set_outputBuffer("In Final, exiting.");
platform->next_state();
}
}
// -- ^^^ new ^^^ -- ;; no extra parentheses
void ABStar::Final() {
platform->enter_state();
if (( platform->get_nextChar() == 'a' )) {
platform->set_outputBuffer("In Final, found A");
platform->next_state();
NeedB();
} else if (( platform->get_nextChar() != '\0' )) {
platform->set_outputBuffer("In Final, found something other than B");
platform->next_state();
Error();
} else if (( platform->get_nextChar() == '\0' )) {
platform->set_outputBuffer("In Final, exiting.");
platform->next_state();
}
}
// -- or --
void ABStar::Final() {
platform->enter_state();
if (( platform->get_nextChar() == 'a' )) {
platform->set_outputBuffer("In Final, found A");
platform->next_state();
NeedB();
}
else if (( platform->get_nextChar() != '\0' )) {
platform->set_outputBuffer("In Final, found something other than B");
platform->next_state();
Error();
}
else if (( platform->get_nextChar() == '\0' )) {
platform->set_outputBuffer("In Final, exiting.");
platform->next_state();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment