3 ms·
I could see this as an effective pedagogical tool when learning to program.
by lalos 7y ago
I could see this as an effective pedagogical tool when learning to program.
- helloiloveyou 7y agoThank you! That's really what this post is about :) Facing the loop's body so many times forces you to analyze if something better can be done
- necovek 7y agoIn real world, factoring out a function that's only ever used once is usually not the smartest thing to do early. You'd do that if you eg. do TDD. The article is a false "tip": author explicitely decides not to extract the entire loop body (why?) into a function but only a part of the logic. They've chosen the factoring approach despite no loop, not thanks to it. Their intrinsic reasoning that led to deciding what to split out would have been more useful, and then we could argue if it was good design tip or not.