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
@m0xee lol indeed.
Now, do you know what's the one kind of data that absolutely should be both mutable and shared, which goes against Rust philosophy? Fucking mutexes! And also every other kind of synchronisation primitive.
My post was inspired by kernel people complaining literally about this.
@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
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.
@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?