Last active
March 21, 2019 02:14
-
-
Save GeePawHill/0be0ae51d8f7464903dc242d6294b471 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
longMethod( int y ) { | |
int x; | |
x = 0; | |
// ... | |
// IRRELEVANCY #0: 87 lines that neither read nor write x | |
// ... | |
if( y == 17 ) { | |
x = 1; | |
} | |
// ... | |
// IRRELEVANCY #1: 87 more lines that neither read nor write x | |
// ... | |
if( someVeryInterestingConditionHavingNothingToDoWithX() ) { | |
doTheThing(x) | |
} | |
// ... | |
// IRRELEVANCY #2: 87 more lines that neither read nor write x | |
// ... | |
} | |
//////////////// | |
// After joining declartion to initialization and moving it as far *down*... | |
// we can go 87 lines into this method *without* having to remember what X is. | |
longMethod( int y ) { | |
// ... | |
// IRRELEVANCY #0: 87 lines that neither read nor write x | |
// ... | |
int x=0 | |
if( y == 17 ) { | |
x = 1; | |
} | |
// ... | |
// IRRELEVANCY #1: 87 more lines that neither read nor write x | |
// ... | |
if( someVeryInterestingConditionHavingNothingToDoWithX() ) { | |
doTheThing(x) | |
} | |
// ... | |
// IRRELEVANCY #2: 87 more lines that neither read nor write x | |
// ... | |
} | |
//////////////// | |
// After extraction we killed an if and made the single-assign aspect of x obvious | |
// in languages with immutability, we just made x immutable (const)! | |
longMethod( int y ) { | |
// ... | |
// IRRELEVANCY #0: 87 lines that neither read nor write x | |
// ... | |
int x=chooseX(y) | |
// ... | |
// IRRELEVANCY #1: 87 more lines that neither read nor write x | |
// ... | |
if( someVeryInterestingConditionHavingNothingToDoWithX() ) { | |
doTheThing(x) | |
} | |
// ... | |
// IRRELEVANCY #2: 87 more lines that neither read nor write x | |
// ... | |
} | |
//////////////// | |
// We keep moving it down, but now it's easy to see we can move it *in* | |
// Now we've made IRRELEVANCY #1 visibly irrelevant, and IRRELEVANCY #2 visibly irrelevant | |
longMethod( int y ) { | |
// ... | |
// IRRELEVANCY #0: 87 lines that neither read nor write x | |
// ... | |
// ... | |
// IRRELEVANCY #1: 87 more lines that neither read nor write x | |
// ... | |
if( someVeryInterestingConditionHavingNothingToDoWithX() ) { | |
int x = chooseX(y) | |
doTheThing(x) | |
} | |
// ... | |
// IRRELEVANCY #2: 87 more lines that neither read nor write x | |
// ... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment