crabs, explain yourselves

whats the rationale behind removing static variables from rust?

Shopping Cart Returner Shirt $21.68

DMT Has Friends For Me Shirt $21.68

Shopping Cart Returner Shirt $21.68

  1. 1 month ago
    Anonymous

    >troon avatar
    every time

  2. 1 month ago
    Anonymous

    the only way to keep our programs heckin safe is to ban everything non-static and mutable. user input should be banned altogether

    • 1 month ago
      Anonymous

      kek

      >troon avatar
      every time

      such is their community

  3. 1 month ago
    Anonymous

    Static variables are safe and will not be removed.
    To make a static variable mutable you can do two things:
    - Add some sort of synchronization (a mutex, atomics, etcetera), to deal with thread safety and reentrancy
    - Use `static mut`, which requires unsafe {} to access
    It's easy to mess up usage of `static mut`, so they're considering deprecating it in favor of using UnsafeCell, which goes through raw pointers and makes it easier to think about what you're doing. This has all the same capabilities with a different API.
    This would only take effect on projects that opt into the 2024 edition and it's not very hard to switch. (And if you don't opt into the 2024 edition you may miss out on on a few bits of new syntax but you can still use most new features.)
    tl;dr somebody misread a blog post

    • 1 month ago
      Anonymous

      thanks for the answer.
      makes sense from the standpoint of rust- put a big red flag on it

    • 1 month ago
      Anonymous

      This. Just use unsafe

      • 1 month ago
        Anonymous

        static mut is already unsafe
        Your go-to solution should be to slap on a OnceLock or Mutex or RwLock

        • 1 month ago
          Anonymous

          No it shouldn't. SDL itself doesn't support concurrency so it HAS to be used single threadedly. Mutex is bloat if it will never be used in multithreaded environment anyway. Just wasted performance
          Just use unsafe here, it's not that scary

          • 1 month ago
            Anonymous

            If you're writing a wrapper for an enormously complicated library then you shouldn't necessarily pick the go-to solution yeah, I didn't realize that was what you meant
            But if you just ignore the problem then your wrapper will shit itself if you use multiple threads and you're technically required to mark your whole API unsafe. One thing you could do (perhaps not the best solution) is to have a non-Send/Sync zero-sized handle you have to acquire to call the functions, so that you can lock the mutex once on startup and then guarantee at no further runtime cost that you use the library from a single thread
            >Just use unsafe here, it's not that scary
            You need to be extra paranoid if you're writing a library

  4. 1 month ago
    Anonymous

    I don’t know anything about Rust, but static mutable variables are conceptually weird and are only good for singletons. There’s probably some optimisation they can make if they dump it from the language completely.

    • 1 month ago
      Anonymous

      rustc doesn't really do much optimization.
      Most of the optimization is done on the LLVM IR by LLVM.

      • 1 month ago
        Anonymous

        >all the heavy lifting is done by a compiler toolchain written in c++
        not only does the language not even have a specification, it practically doesn't exist by itself, it's just some transpiler

        • 1 month ago
          Anonymous

          lel it isnt even bootstrapped

      • 1 month ago
        Anonymous

        It optimizes by telling LLVM what it's allowed to do. That post isn't entirely wrong, references to statics are restrict by default just like other references and so already get optimized in fricky ways

        >all the heavy lifting is done by a compiler toolchain written in c++
        not only does the language not even have a specification, it practically doesn't exist by itself, it's just some transpiler

        There are a couple of different codegen backends

        • 1 month ago
          Anonymous

          >There are a couple of different codegen backends
          both cranelift and the gcc backend are not stable

          • 1 month ago
            Anonymous

            They exist though

  5. 1 month ago
    Anonymous

    lmao i was banned for posting this shit earlier, what a joke of a language and community rust are. stay vigilant boys, they dont want you talking ill of their shitty delusions, just like with their rotten disease ridden bodies.

  6. 1 month ago
    Anonymous

    >please make huge api changes to suit my troony langy
    every time. maybe they should just like make their own abstraction layer and make huge updoods for it

  7. 1 month ago
    Anonymous

    >static mutable variables
    What is the issue? If you are trying to write good code you wouldn't be using mutable statics in the first place. The only people who use them are morons or bad programmers who bring nightmares to other devs 10-20 years down the line. I can personally attest to these things giving me nightmares on a daily basis at work.

    • 1 month ago
      Anonymous

      what if: cache, perfect for static mutable globals

    • 1 month ago
      Anonymous

      moron here, why even make it a variable if it's *not* going to be mutable?

      • 1 month ago
        Anonymous

        You can use it to embed data that's known at compile time

  8. 1 month ago
    Anonymous

    >Hey guys I would like to suggest breaking everything for everyone else because I personally shit the bed.

Your email address will not be published. Required fields are marked *