Refactor Complex Code via Simple Steps
The code smells seen so far all stem from overly long classes and functions. Take ReactFiberCommitWork as a prominent example: its three central functions span 200 to 400 lines of code each. This raises the question: should we prefer many small methods—the logical outcome of the recommended refactorings—or is it better to keep related code in one large chunk?
The main advantage of modularizing a piece of code isn’t that we get shorter functions. Rather, it’s about transforming the context, as discussed in design to isolate change. By extracting cohesive, well-named functions, we introduce chunks into our design, as shown in the following figure. These chunks let us reason more effectively about the problem ...
Get Your Code as a Crime Scene, Second Edition, 2nd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.