Created
August 24, 2018 19:05
-
-
Save kellenmace/beb35925fb35b7b19d04b7fbd293a56a 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 | |
$projects = wds_get_projects(); | |
// ...do some work... | |
$active_projects = array_filter( $projects, function( $project ) { | |
return 'active' === $project['status']; | |
}); | |
// ...do some work... | |
$active_microsoft_projects = array_filter( $active_projects, function( $project ) { | |
return 'microsoft' === $project['client']; | |
}); | |
/* | |
Because we're setting the values of these variables once and then never | |
changing them (a.k.a. leaving them immutable), a developer unfamiliar | |
with this project could open up this file and easily determine what each | |
of them is equal to at any point. That would NOT be the case if the $project | |
variable started off storing all of the projects, then later on it was | |
changed (mutated) to represent just the active projects, then later on it | |
was changed again to represent the active Microsoft projects. | |
Immutability FTW! | |
P.S. Breaking this up into smaller, single-purpose functions would be even | |
more of an improvement and would rule out the need for so many variable | |
names in many cases. | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment