3 ms·
What do you mean by top-down? I'd say it encourages bottom-up programming since scoped functions are so light weight. Scoped functions can easily be made global
by pederbl 14y ago
What do you mean by top-down? I'd say it encourages bottom-up programming since scoped functions are so light weight. Scoped functions can easily be made global when it makes sense to share the logic.
- lmm 14y agoI mean top-down as in writing high-level functions first and then writing the lower-level functions which they call afterwards. It's already a tempting (but inferior) way to program; with this function order it would be very easy to write main() first and work down from there, hoisting inner functions out as necessary.
- pederbl 14y agoThe main problem with top-down programming that I have understood is that it tends to lead to non-DRY code (i.e. functions repeat the same logic and patterns). I have noticed that my code becomes much more DRY with this new approach because it becomes more obvious when I am repeating functionality/patterns and it becomes easier to break such functionality/patterns out to become generalized global functions when appropriate. This is especially true for patterns since local variables are often the main reason for why patterns do not tend to get separated out into new functions.
- lmm 14y agoNope; the problem is that it gives you more opportunity to make mistakes, because you're not using your freedom effectively. Your low-level functions are generally far more constrained than your high-level ones (you often have complete freedom over main()); by writing them first you make the constraints on your high-level program design more apparent before you write it, and reduce the risk of structuring your high-level functions wrongly.