4 ms·
Function abstraction is not only about reuse, it's about separating the high level details from the low level details. Separating the flow of logic, from the de
by zorga 8y ago
Function abstraction is not only about reuse, it's about separating the high level details from the low level details. Separating the flow of logic, from the details of each step, is always valuable and should be done right from the start; replacing an inline implementation with a function name with args is abstraction even when it's not ever reused and it greatly improves the code.
Big methods that do many things inline with commented sections explaining what the section does, is bad programming. It allows variable reuse and hidden weird dependencies between what should be independent chunks of code in independent functions. It also forces the programmer reading it to always work at the lowest level of implementation rather than a higher level of abstraction where he can see the flow without needing to see all the details of each step. If you can point to a section of code, and put a comment on it saying it does X, then it belongs in a function named X and the comment needs deleted. Comments that explain what code does are a code smell. Comments are for explaining why, not what.
There shouldn't be any big functions to begin with except in a few rare cases like switching on a character or something.