Created
November 8, 2012 16:09
-
-
Save till/4039765 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// not so great: | |
if ($blah) { | |
$doSomething; | |
} else { | |
throw Exception(); | |
} | |
// better: | |
// be explict | |
// no need to overcomplicate with else | |
if (false === $blah) { | |
throw Exception(); | |
} | |
$doSomething; | |
// Also good in methods: | |
function foo() | |
{ | |
if ($somethingDidntWork) { | |
return; // this exits from the method, no need to "else" | |
} | |
$doSomething; | |
andMore(); | |
return 'whatever'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment