(no title)
oblvious-earth | 2 years ago
But "globals" and "composable standalone functions" are contradictory, if you're mutating global state your function is neither composable nor standalone.
What you've got is a poor mans class instance using global instead of self.
knowsuchagency|2 years ago
oblvious-earth|2 years ago
It's over 1200 lines of code, it's not like it's 100 lines of code and can fit on a single screen
> Globals are fine--they're even marked as such
I would argue that globals in this context are not fine from a code maintainability point of view.
By using globals here it's hard to know from a function call if it's going to mutate global state or not. If all the functions were methods of the same class instance, and other functions were just functions or part of some other class, then it gives you a clear grouping of calls which are related to mutating that state.
In general I would argue if you are ever in the situation of "I have more than two or three functions that are related to each other and they all need to mutate the same state so I use a mutable global" or "I pass around the mutable state via arguments" then make a class! It creates an obvious semantic grouping of callables.