Re:I Like and Use Global Variables
by banthar on Monday February 10, 2025 @05:51AM
(#42998977)
You can make globals thread safe by using thread locals. You can make methods using them reentrant by carefully saving and restoring state. What about exceptions? Any exception from `process()` is going to leave this global state in a total mess.
[ Parent
| on HN ]
Re:I Like and Use Global Variables
by levodelellis on Tuesday February 11, 2025 @02:16AM
(#43009922)
I should have talked more about that in the article. I mentioned defer, making functions reentrant, etc, but languages with exceptions and without defer can make things much harder. I tried to make it clear the global state should be accessible from a handful of functions or within a file/module