logoalt Hacker News

johnisgoodyesterday at 11:02 AM11 repliesview on HN

Off-topic, but I seriously dislike the syntax of Rust. It is chaotic and mind-boggling to me. See the "insert" function.

Good post though.


Replies

Mond_yesterday at 12:46 PM

This point has been litigated to death. Read this here: https://matklad.github.io/2023/01/26/rusts-ugly-syntax.html

Almost everything that people think is ugly about Rust's syntax exists for very specific reasons. Most of the time, imo Rust made a good decision, and is just making something explicit.

Some things take time to get used to (e.g. if let), but for most people that's less an issue of syntax, and more an issue of not understanding a powerful feature (e.g. pattern matching deconstructions).

show 5 replies
ikkunyesterday at 11:32 AM

as a beginner rust programmer, I agree. it takes me way longer to parse someone else's rust code than it does for me to read C or C++, even though I have about the same amount of experience with them. in that example, I had to look up what "if let Err() =" does, because it's not intuitive to me. it seems like every time I read rust code, I have to learn about some strange feature that's probably convenient when you know it, but there's a billion of them and they add up to hard to read code until you've spent tons and tons of time with rust. it's just so much to memorize compared to other languages.

show 2 replies
Sharlinyesterday at 11:17 AM

It takes at most a week to get used to just about any syntax. It should absolutely never be a reason not to try a new language. That said, it would be lovely if Rust had a more ML-like, rather than C-like, syntax (being originally inspired by O’Caml), but that would likely not help attract devs in the intended target audience!

The insert function, for what it’s worth, has nonstandard formatting; the de facto standard rustfmt tool would use more newlines, making it clearer and less dense. The function also uses a couple of syntactic features like `if let`, which may seem unfamiliar at first but become second nature in a few days at most.

show 3 replies
figassisyesterday at 11:12 AM

It’s promises make me interested, but the syntax is my main turnoff. I am a Go person, and I think what brings people to go is the opposite of what brings people to Rust. I am willing to sacrifice some memory safety (because I maybe naively think I can manage to write software without many memory bugs) for the simplicity and dev experience that Go offers.

Levitatingyesterday at 11:53 AM

The first statement defines a closure. The second is an if-let statement. It's not chaotic, you're just unfamiliar with the syntax.

I actually find the Rust syntax very natural, more than C in some areas.

show 1 reply
mpalmeryesterday at 11:28 AM

It really reads quite simply once you're familiar with the language. You only see chaos because there are none of the semantic hooks you'd get from experience

show 1 reply
6r17yesterday at 11:50 AM

tbh it's bit boring to get stuck on aesthetic of writing up something. It's a bit nauseous to see how this place is hostile to rust for no reason other than "it's not pretty". It's a joke at this point we could make caricature of HN viewpoint on rust. We get it, you don't like it.

show 2 replies
neonz80yesterday at 1:05 PM

I find the short type names for integers and float hard to read. Somehow the size of the type is more important than if it is a signed integer, unsigned integer or a floating point number.

Using Vec for arrays is also annoying, repeating the mistake from C++.

show 2 replies
ozgrakkurtyesterday at 12:16 PM

For me it is the usage of macros and traits everywhere.

Good luck if you want to get into the code of a library to understand what a function does. You have to go through 3 macros and 5 traits across 5 files. When it could have been just a couple function calls.

People don’t stop and think if they really need that trait or macro for five seconds, they just have to use it every time

show 1 reply
cannonpalmsyesterday at 1:40 PM

The insert function is very unidiomatic. Instead of defining a cmp closure, you would typically implement Ord and friends.