3 ms·
So in someways, the best generalization like this I already commonly see is a capabilities system, which can be done essentially via function parameters. I've u
by kjeetgill 5y ago
So in someways, the best generalization like this I already commonly see is a capabilities system, which can be done essentially via function parameters. I've used this as an OOP pattern once or twice and I think it's the easiest way to explain it:
Imagine you have 2 singleton objects in your 'void main()', redkey and bluekey of types Redkey and Bluekey.
Somewhere else, you declare your function: 'int foo(Redkey redkey, int x, int y)' that needs a Redkey object of which only one exists: in your main.
This by itself forces every call on the path between 'main()' and a call to 'foo()' to also include a parameter Redkey.
In the extreme cases where a pattern like this is useful (tracing IO calls, you named it) it can really help cut through a codebase after an hour of refactoring. But it can be limiting. Async and Checked Exceptions are probably the most colored functions and they both need escape hatches because of that.