5 ms·
Yeah, I see this all the time. Giant 600 line functions made of nested for loops, with all sorts of shit going on at each layer. The author will insist it's ba
by s_kilk 11y ago
Yeah, I see this all the time. Giant 600 line functions made of nested for loops, with all sorts of shit going on at each layer.
The author will insist it's basically impossible to abstract any of it, that the for-loops are the only way to capture the essence of the problem.
Then you spend two days tracking down a bug in there and discover that it's all actually some combination of map, reduce and a fold with a closure at heart.
- visarga 11y agoMaybe the solution is to break the large function into several smaller ones, even if they still make use of for loops.
- michaelfeathers 11y agoNo doubt. But once it gets to a certain point the costs of doing that are much larger than having started in a compositional style. If you have Martin Fowler's Refactoring book, check out the intro example. It's a 20 line function and the amount of refactoring work he does on it to make it sensible is quite large.