3 ms·
Generalizing even when you are only using your solution once can sometimes be useful. When you know that certain information should not be used in a correct so
by eru 7y ago
Generalizing even when you are only using your solution once can sometimes be useful.
When you know that certain information should not be used in a correct solution, a more abstract approach can make sure that information stays hidden.
A really simple example: for-loops in Python 'leak' their index variable. Stick that loop inside a local function, and then you know that you can not accidentally make use of the index variable later.
A more complicated example is deliberately coding to an interface that carefully exposes only what should be exposed. Eg using a map or filter higher-order function.