News for hackers. Stuff that matters.
Re:Thoughts on Go vs. Rust vs. Zig by dxxvi on Thursday December 04, 2025 @08:22PM (#46155741)
> It's exceedingly rare to see any sort of global mutable state I know a bit of Rust, so you don't need to explain in details. How to use a local cache or db connection pool in Rust (both of them, IMO, are the right use case of global mutable state)?
Re:Thoughts on Go vs. Rust vs. Zig by adastra22 on Thursday December 04, 2025 @09:47PM (#46156325)
You wrap it in a mutex and then it is allowed.

Global state is allowed. It just has to be thread safe.

Re:Thoughts on Go vs. Rust vs. Zig by therein on Thursday December 04, 2025 @08:30PM (#46155797)
Why does that have to be global? You can still pass it around. If you don't want to clobber registers, you can still put it in a struct. I don't imagine you are trying to avoid the overhead of dereferencing a pointer.
Re:Thoughts on Go vs. Rust vs. Zig by spacechild1 on Friday December 05, 2025 @03:23PM (#46166764)
I think a better example might be logging. How is this typically solved in Rust? Do you have to pass a Logger reference to every function that potentially wants to log something? (In C++ you would typically have functions/macros that operate on a global logger instance.)
Re:Thoughts on Go vs. Rust vs. Zig by whytevuhuni on Saturday December 06, 2025 @01:33PM (#46175491)
In Rust you typically use the "log" crate, which also has a global logger instance [0]. There is also "tracing" which uses thread local storage.

As another comment said, global state is allowed. It just has to be proven thread-safe via Rust's Send and Sync traits, and 'static lifetime. I've used things like LazyLock and ArcSwap to achieve this in the past.

[0] https://docs.rs/log/latest/log/fn.set_logger.html

Re:Thoughts on Go vs. Rust vs. Zig by dxxvi on Saturday December 06, 2025 @04:22AM (#46171885)
I wonder what the advantage of passing it around is when it makes the argument list longer. The only advantage that I can see is that it emphasizes that this function does something with cache.