“you cant use global variables because it can create data races” have you ever heard of a mutex
-
“you cant use global variables because it can create data races” have you ever heard of a mutex
-
Laxystem (Masto/Glitch)replied to notsludgebomb (Adwaita-moding) last edited by
@notsludgebomb global state is bad for duplciatability and testability too.
-
notsludgebomb (Adwaita-moding)replied to Laxystem (Masto/Glitch) last edited by
@laxla how is it bad for testability
-
Laxystem (Masto/Glitch)replied to notsludgebomb (Adwaita-moding) last edited by
@notsludgebomb take, for example, KotlinX Coroutines
Its test library lets you use some kind of reflection hack to replace the global state default dispatcher. If not for that being intentionally put in, you simply couldn't test things properly
While some kinds of global state theoretically don't hurt, you don't know where it'll bite you, so it's good practice to just pass it down as a dependency.
Copyright © 2024 NodeBB | Contributors