|
|
|
|
|
by wgerard
1340 days ago
|
|
My personal addition: Code isolation I've "prematurely" split up code across multiple/classes functions so many times before these huge god functions became set-in-stone and unwieldy. I had a co-worker once who was extremely heavy on YAGNI--and I don't mean that as a pejorative, it was a really helpful check against code solving non-existent problems. They once called me out on a refactor I'd done surreptitiously for a payments flow to split payment states into multiple classes. Serendipity had struck, and I was able to point to a submitted (but not accepted) diff that would've broken the entire payments flow (as opposed to just breaking one state of the flow). I always think about that every time I question whether I'm isolating code prematurely. |
|
* If breaking up the code makes it easier to understand with its current functionality then absolutely go ahead.
* If breaking up the code makes it slightly less easy to understand right now, but will make it easier to add some feature later that you know you know you're definitely going to need, then hold off.
Most of the time you "know" you're going to add a feature, you turn out to be wrong, and (worse than that) some other slightly different feature is needed instead that's actually harder to add because you broke up the logic along the wrong axis. Whereas, breaking code up purely based on what makes it easier to understand now, ironically, usually does a much better job at making it easy to add a feature later - it often almost feels like an accident (but it's not, really).
I bet your payment flow refactoring made things a bit easier to understand, even if it had never been worked on again.