3 ms·
> Surely if you can mutate a state object and pass it, its state can get mutated equally deep within the codebase no different than a global, no? Yes, that's o
by Tainnor 2y ago
> Surely if you can mutate a state object and pass it, its state can get mutated equally deep within the codebase no different than a global, no?
Yes, that's one reason why shared mutable state should IMHO be kept to a minimum and immutable objects/structs should be preferred.
// this function will implicitly look up the tenant from some global context
fun createUser(username: String, password: String)
vs.
fun createUser(username: String, password: String, tenant: Tenant)
except imagine that the comment for that first function didn't exist (because nobody documents shit anymore these days).
The second one is almost impossible to accidentally misuse, the first one can lead to all sorts of weird bugs.