At this point, you may start to see clusters of functionality. My 12-branch conditional was down to 6. Not done yet though...
-
-
Replying to @sarahmei
8. Find any outlier cases (i.e. that have a differently-structured outcome) & remove them. Make them guard clauses instead.
1 reply 2 retweets 9 likes -
Replying to @sarahmei
Now all the remaining branches of the if-elseif are related. This is the conceptual center of the conditional.
1 reply 4 retweets 9 likes -
Replying to @sarahmei
9. Give any remaining boolean statement containing || or && a name. Make it a non-programmery name. Figure out what concept it represents.
1 reply 3 retweets 12 likes -
Replying to @sarahmei
Often just naming the branches shows me more simplifications I could make. Similarities hidden in the morass of nesting are suddenly plain.
1 reply 2 retweets 9 likes -
Replying to @sarahmei
10. With the concepts clear, (cautiously) re-introduce abstractions. No new conditionals!, but pull out bleedingly obvious duplication.
1 reply 2 retweets 7 likes -
Replying to @sarahmei
11. Rearrange the conditional so that the most likely case is in the `else`, and the rest are exceptions.
2 replies 4 retweets 12 likes -
Replying to @sarahmei
Remember: inebriation test. Can a developer come in & quickly determine how many codepaths there are, & what's the most likely one to run?
3 replies 6 retweets 13 likes -
Replying to @sarahmei
At this point, if you are an OO-dedicated person, you might start to see small objects in these branches. Sometimes I see them...
1 reply 0 retweets 7 likes -
Replying to @sarahmei
But usually I have a story I'm working on, so I'll probably leave the code at this point. If I have to change it again, I'll do the objects.
2 replies 0 retweets 5 likes
I find that types in TypeScript dramatically up the chance I'll refactor into a bunch of small objects
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.