Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Can you elaborate on what exactly you don't like about Rust's syntax? I'm always surprised when I hear this, because a lot of the things that get pointed out tend to have good reasons for the way they are.


But it doesn't matter. If the language is unreadable, even if every syntactic decision followed by necessity alone from a set of first principles, it wouldn't prove the language was readable. It would only prove the selected principles necessitate an unreadable language.

Compare [x for x, y in v] to v.iter().map(|&(x,y)| x).collect::<Vec<_>>(). There is a good reason for every bit of ugliness, but that does not change the fact that it is ugly.


I agree that the snippet you gave is ugly, but I also think that it's not really the most straightforward way to right it. Any time the type that you're collecting into isn't inferred, you're free to define a binding and just type annotate it. Also, the lambda you gave is not defined in the straightforward way I think most people would define it. Putting those together, you get something like this:

``` let vec: Vec<_> = v.iter().map(|pair| pair.0).collect(); ```

I don't think that's really _that_ ugly. Yes, the pithy Python example you gave is simpler, but by the same token, the assembly you would write to achieve this makes the Rust look really simple. If you're going to try to write efficient code in a systems language like Rust, you're going to need to express things more precisely than you would in a scripting language like Python.


Readability is very often nothing else but habit - code which looks like code you've seen often enough looks well. Case in point: The first example is just gibberish to me and I needed the second one to decipher it.

Also, I would write the second example different:

  let r: Vec<_> = v.iter().map(|(x,_)| x).collect();
In my opinion that's superior in readability to both of your examples, but probably also only because I'm used to it.


Your r has a different type.


The lambda syntax, to me. Why go Ruby |it| instead of Groovy it -> ? The first one is ugly. Maybe for easier parsing?

Then ' for lifetimes. Personally I like short keywords. Maybe "life"?

Then there are the <> generics which some don't like.

And most modern languages don't have references anymore plus & was always ugly and non intuitive as a symbol. Again, maybe a short keyword? "ref"?


These all seem like small personal preferences to me, which are entirely valid; I don't think it's possible for a language to have a syntax that pleases everyone. But the comment I was responding to described Rust as having an "awful readability problem", and I don't really see that being described here. In particular, the comment I was responding to described Java as having "stellar readability", so mentioning the generic syntax of Rust really surprises me. Is `Foo<? extends Bar>` really so much better than `Foo<T: Bar>`?


Rust takes inspiration from several disparate sources. There’s something for everyone to find a bit alien. (That’s my working theory at least)


PL/I has done it, famously, and just as famously the language has turned out horribly misdesigned and complex, and it also has missed out on most new ideas. (Still in use though.)




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: