6 ms·
In general, abstracting code out into functions can be useful, even when the new functions is only called once. That is because functions are a well understood
by eru 14y ago
In general, abstracting code out into functions can be useful, even when the new functions is only called once.
That is because functions are a well understood abstraction. And having code separated into functions makes it easier for the reader to deduce the coupling points: two blocks of code after another can have all kinds of weird dependencies, e.g. the first blog might set some local variables that the second one relies on. But functions just have arguments and return-values.
- mattmanser 14y agoObviously. I've found in my experience working with other people's code and maintaining large code bases you find that overly nesting functions causes a lot of problems when you're trying to read or debug code. You often also see problems where the essentially dependant functions start to separate in the code as people accidentally add new functions between them. The article I linked is good, John describes it well. It's a nightmare to work with when you get triple or quadruple nesting of tiny functions, like in the code of this program. It's totally unnecessary.
- eru 14y agoI guess it also depends a bit on the language you are working in. Some languages have an easier time dealing with functions. In, say Haskell, having quadruple nesting of tiny functions isn't too much of a problem---and if you are pedantic, is the only way to create a function with four arguments.