In the year of our Lord and Saviour 2024, Rust - the language that promised to save us from the scourge of writing C - still doesn't allow to declare and initialise a static variable. Just because.
Instead of a robust systems programming tool, all we got is a retarded JavaScript on steroids. So much disappointment.
@icon_of_computational_sin
You can declare a variable with static lifetime, but having a static variable in C sense, considering the borrow checker, would be kinda against the design of the language, you can still do that, but as the compiler can't guarantee thread safety, all modifications to the value of such a variable would have to happen in unsafe block: https://doc.rust-lang.org/reference/items/static-items.html
@icon_of_computational_sin
Yeah, mutices — everyone loves them and uses them. Except for that one time when you were in a hurry (or haven't slept well, which one was it?🤔) and you didn't! Forgot about one in a critical piece of code and it became a bug. But as it only occurs once a year, it wasn't discovered during the initial testing, this code made its way into running on an controller responsible for an air supply of an underwater facility… Aa-argh! People die! Guts and blood everywhere!😱
@icon_of_computational_sin
Still not enough, wanna do it real cowboy style like they did in the good old days with C? Then surely, using the "unsafe" keyword to make that pesky compiler shut the fuck up won't be a problem! It gives you choice — write safe code and optimise just the parts that are critical by resorting to potentially unsafe code, that's good, right?
@icon_of_computational_sin
Rust doesn't allow using static variables — that's a lie: it does! And compatibility with C code is even mentioned as primary use case in the docs. It doesn't make it easy? That's right — it's against its design goals: eliminating potentially unsafe code where it's possible. So what is even your point?
@icon_of_computational_sin
Rust gives you an option to not think about it — like at all: you can have a bottle of vodka in you and just rely on the data types that are being copied — the compiler would tell you to go home and get some sleep if you attempt real silly shit. Slow, takes lots of resources? Well, you can work on that when and if you have time. Want to use mutex in your multi-threaded code? Try one of those Arc<Mutex<T>> ones, they are guaranteed to be atomic, therefore thread-safe.