3 ms·
That just seems like globals with extra steps. Suddenly if your context structure has a weird value in it, you’ll have to check every function to see who messed
by bee_rider 2y ago
That just seems like globals with extra steps. Suddenly if your context structure has a weird value in it, you’ll have to check every function to see who messed it up.
- bigcat12345678 2y agoThat's 2 parts: 1. Global variable (mutable) 2. Local function with context argument (mutations) You have clear tracking of when and how functions change the global variable
- Joker_vD 2y agoFirst, that's true for globals as well. Second, with "context structure" pattern, the modifications to it are usually done by copying this structure, modifying some fields in the copy and passing the copy downwards, which severely limits the impact radius and simplifies tracking down which function messed it up: it's either something above you in the call stack or one of the very few (hopefully) functions that changes this context by-reference, with intent to apply such changes globally.