3 ms·
I wouldn't say that procedural code relies on global variables, but I would say that we find ourselves worrying about execution order a lot more when using proc
by chriswarbo 13y ago
I wouldn't say that procedural code relies on global variables, but I would say that we find ourselves worrying about execution order a lot more when using procedures rather than pure functions.
If we care about execution order, we tend to avoid higher-order patterns which may defer execution (eg. compose) or give a nondeterministic order (eg. map). If we avoid higher-order patterns, we end up hard-coding an awful lot of control-flow, which makes our code less re-usable.
Simplistic attempts to avoid this, introduce a small amount of higher-order behaviour, like passing around 'callbacks', but this can be cumbersome and add a lot of boilerplate. Of course, the solution to avoiding this is to use even more powerful higher-order functions (like monadic bind) to handle the callbacks for us, but since we're trying to avoid as much higher-order behaviour as possible, this tends not to be done.