Skip to content

Instantly share code, notes, and snippets.

@2shortplanks
Created April 28, 2016 16:57
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 2shortplanks/239dd10275571a44aa4f3ffd9be36b56 to your computer and use it in GitHub Desktop.
Save 2shortplanks/239dd10275571a44aa4f3ffd9be36b56 to your computer and use it in GitHub Desktop.
Don't have unreachable code!

I said I hated the code on http://imgur.com/gallery/ZM0lYhb/ and StillNotYouTube asked for a better explanation. So here it is

if (foo == bar) {
  return "foo is bar";
} else {
  return "foo is not bar";
}

Is bad form. I would like:

if (foo == bar) {
  return "foo is bar";
}
return "foo is not bar";

There's several reasons for this is better For example, in the first code example I have to worry what the routine returns after the if/else (i.e. I actually have to work out it's unreachable and that I shouldn't worry about that)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment