3 Shatter long functions
This chapter covers
- Identifying overly long methods with Five lines
- Working with code without looking at the specifics
- Breaking up long methods with Extract method
- Balancing abstraction levels with Either call or pass
- Isolating
if
statements withif
only at the start
Code can easily get messy and confusing, even when following the Don’t Repeat Yourself (DRY) and Keep It Simple, Stupid (KISS) guidelines. Some strong contributors to this messiness are as follows:
-
Methods are doing multiple different things.
-
We use low-level primitive operations (array accesses, arithmetic operations, etc.).
-
We lack human-readable text, like comments and good method and variable naming.
Unfortunately, knowing these issues is not ...
Get Five Lines of Code 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.