Created
July 29, 2016 11:17
-
-
Save billforward-alex/3fc708c8a5c69c3104b575e55fee3b9a 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 | |
public function eatIfHungry() { | |
// states we need to think about: | |
// - isHungry | |
// - !isHungry | |
if (!$this->isHungry()) { | |
// states we need to think about: | |
// - !isHungry | |
return; | |
} | |
// states we need to think about: | |
// - isHungry | |
// nice! we permanently eliminated a branch. | |
// the number of states we need to consider only ever decreases | |
$this->eat(); | |
} | |
public function eatIfHungry() { | |
// states we need to think about: | |
// - isHungry | |
// - !isHungry | |
if ($this->isHungry()) { | |
// states we need to think about: | |
// - isHungry | |
$this->eat(); | |
} | |
// states we need to think about: | |
// - isHungry | |
// - !isHungry | |
// sad :( conditions that were ruled-out inside the `if` have come back | |
// the number of states we need to consider keeps changing: | |
// we need more contextual awareness to code like this | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment