3 ms·
You misunderstand, I think. Or maybe I do. If done properly as described, the functions accept state. This means they adjust state by adjusting input/output pa
by jvanderbot 7y ago
You misunderstand, I think. Or maybe I do.
If done properly as described, the functions accept state. This means they adjust state by adjusting input/output parameters, not by affecting some internal state. This is basically Dependency Injection extended to state. This is also how classes are implemented (see python's self parameter to all class functions).
- BiteCode_dev 7y agoYes, but looking at the function, and banning some project specific naming convention, there is no way to know its role is to mutate a state. While in Python, when you see a class, you just know the methods are mostly about "self". It helps making sense of the code immensely.
- jvanderbot 7y agoCorrect, but the effectiveness of the design is separate from its correctness. Latter of which is what I commented on. For effectiveness, I think it reduces ancillary class members, and encourages (necessitates!) dependency injection. For example, changing "delta t" in a game object update is trivial: update the one delta-t you have, and pass it into everything that needs it. With classes, there may be a temptation to have a delta-t member variable, which costs many updates. Stupid example, but a mistake which is not possible with Dependency Injection. But really, proper scoping in typed languages (and naming in dynamic ones) can allude to input vs output parameters. In C/C++ this is passing by ref vs value. (In Google C++ style guide, they recommend use of pointers for "adjusted" or "output" parameters.) In MS C++ from back in the day, I think they had ways to explicitly specify parameters as input, output, or input+output. Does someone have an example of this?
- bhandziuk 7y agoplus favoring mutability over immutability opens up a whole other can of bugs
- hhas01 7y agohttps://en.wikipedia.org/wiki/Abstract_data_type https://en.wikipedia.org/wiki/Abstract_data_type
- Udik 7y agoIt would be nice to group all the functions that operate on a piece of state together in the same place. It would also be nice to prevent functions that are not in this group to make changes to that part of the state. Then you could prefix all those functions with a name, so it's clear what's their scope. Finally, in some cases it would be great if you could create multiple independent "instances" of the state, so you could manage more than one at a time without risking conflicts between the various copies.
- jvanderbot 7y agoWell, they can still be grouped by module, header, and/or namespacing