This was a really good summary of what Rust feels like in my opinion. I’m still a beginner myself but I recognize what this article is saying very much.

The hacker news comments are as usual very good too:

https://news.ycombinator.com/item?id=40172033

  • onlinepersona@programming.dev
    link
    fedilink
    English
    arrow-up
    6
    arrow-down
    1
    ·
    7 months ago

    Fearless refactoring is a huge benefit of Rust.

    That’s not the issue. The issue is the borrow checker making things slower to write. Changing requirements isn’t just moving code back and forth, it’s changing the existing code, moving it around, adding new dependencies, using existing code in a new way, and so on. Not easy to do if the borrow checker is screaming at you about some moved ownership.
    That’s what dynamically typed languages are good at: pass in a dict/object/hashmap/whatever with some attributes to test something out, pass that around, transform it, add keys/fields, extract parts of it, transform them and return those, etc., see that it’s working, and then you refactor it with proper typing, linting, and tests where a borrow checker is very very welcome.

    Anti Commercial-AI license

    • asdfasdfasdf@lemmy.world
      link
      fedilink
      arrow-up
      8
      arrow-down
      1
      ·
      7 months ago

      The borrow checker is useful for a lot more than memory safety. This is something I have been repeating for years, but unfortunately people new to the language don’t understand it yet.

      E.g. Rust is the only mainstream language where it isn’t possible to read from a file handle after it’s been closed. There are numerous other common benefits of it that apply to general purpose programming, like not being able to mutate a collection while you’re iterating over it.

      It’s a very common practice in Rust to enforce domain invariants using Rust’s ownership rules, and those things cannot be enforced at compile time in other languages that don’t have ownership.

      The borrow checker is also usually pretty easy to get around with just a bit of experience in Rust.

    • farcaster@lemmy.world
      link
      fedilink
      arrow-up
      5
      ·
      7 months ago

      It’s not like Rust is the first language which requires you to reason about ownership. People still write tons and tons of C++. Rust is much faster to write than C++ in my experience, because ownership is checked by the compiler instead of requiring the human programmer to constantly think and reason about.

      I wouldn’t write gameplay code in Rust like I posted above, but most of the complaints about the borrow checker making Rust somehow exceptionally hard to write are overblown imo. There’s a learning curve but then it makes sense.

    • wkk@lemmy.world
      link
      fedilink
      arrow-up
      4
      arrow-down
      1
      ·
      7 months ago

      Antagonizing the borrow checker is wrong. If it screams it does so to prevent you from writing a mistake. Eventually once you have enough experience you should write code in such a way that doesn’t trip the borrow checker because you know how to properly handle your references.

      Is it difficult to learn at first? Yes, but the benefits of learning this outweighs the downsides such as writing code that may use references when it shouldn’t.

      I’m not a Rust aficionado, but the few Rust I’ve written opened my eyes on issues that I have been dealing with in other languages but for which I was blind.

      Lastly I tried following a Godot project tutorial that was using GDScript except I challenged myself to follow it but rewrite the examples given using Rust’s bindings for Godot. It was definitely more cumbersome to work with, but I might also have been doing something wrong (such as blindly transcribing GDscript instead of writing more idiomatic Rust).

      All of that to say 1) borrow checker is your friend and 2) scripting languages will always be more convenient at the cost of being way more dirty (way less safeties)

      In the end you need to pick the right tool for the job. Multiple tools may be used within the same project.