106
submitted 3 months ago* (last edited 3 months ago) by 1984@lemmy.today to c/rust@programming.dev

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

you are viewing a single comment's thread
view the rest of the comments
[-] onlinepersona@programming.dev 5 points 3 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 7 points 3 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 5 points 3 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 3 points 3 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.

this post was submitted on 27 Apr 2024
106 points (96.5% liked)

Rust

5590 readers
54 users here now

Welcome to the Rust community! This is a place to discuss about the Rust programming language.

Wormhole

!performance@programming.dev

Credits

  • The icon is a modified version of the official rust logo (changing the colors to a gradient and black background)

founded 1 year ago
MODERATORS