News for hackers. Stuff that matters.
Re:Comparing Parallel Rust and C++ by rat9988 on Thursday November 07, 2019 @05:52AM (#21472108)
I don't think it is very hard to parse. I think it is very ugly though. Which kind of makes it unreadable. I mean reading fn is not natural for me. Reading function is way more natural. I feel like the language designers didn't pay attention at all to how natural it will look to developers
Re:Comparing Parallel Rust and C++ by pcwalton on Thursday November 07, 2019 @10:37AM (#21474101)
> I feel like the language designers didn't pay attention at all to how natural it will look to developers

This is not true. We agonized over syntax decisions. "fn" was actually preferred by most of the Rust community.

Re:Comparing Parallel Rust and C++ by jandrese on Thursday November 07, 2019 @01:12PM (#21475674)
I've had the impression that Rust developers come from a more pure-math background than most language designers. People who read mathematical notation all day probably find Rust to be more natural than a typical programming language. For people coming from a traditional computer language background the number of sigils on each line is a point of pain.

IMHO Rust may have tried to roll a little too much into the language. It has the air of the second system effect to it, where every good idea from every language is added together to get something that is less than the sum of its parts and you get code that is hard to decipher until you've learned a full college course worth of syntax.

Re:Comparing Parallel Rust and C++ by pcwalton on Friday November 08, 2019 @12:01AM (#21480073)
I designed the lifetime syntax and I'm far from having a pure math background. There aren't any sigils in Rust that C doesn't have, other than the lifetime syntax, which needs separate syntax as it's a novel feature.

Can you name a specific feature you want removed from Rust?

Re:Comparing Parallel Rust and C++ by jandrese on Friday November 08, 2019 @12:40PM (#21484663)
I'm not sure I'd want it removed, but generics tend to be pretty horrific looking to people new to the language.

An example:

  fn largest<T>(list: &[T]) -> T {
    let mut largest = list[0];

    for &item in list.iter() {
        if item > largest {
            largest = item;
        }
    }
I'm sure experienced Rust devs look at that and say it's fine, but that's definitely a hurdle for new developers.
Re:Comparing Parallel Rust and C++ by slavik81 on Friday November 08, 2019 @09:45PM (#21489220)
You need to specify the properties of T that you use. So, that first line should be:

  fn largest<T: PartialOrd + Copy>(list: &[T]) -> T {
https://tomtongue.com/docs/rust-wk-20.html#trait-bounds
Re:Comparing Parallel Rust and C++ by pcwalton on Friday November 08, 2019 @02:22PM (#21485745)
What would you want to see instead? That's pretty much the same syntax as generics in Java.
Re:Comparing Parallel Rust and C++ by blub on Thursday November 07, 2019 @10:46AM (#21474185)
Then the only reasonable conclusion is that the Rust community has different tastes compared to the mainstream programming community. To put it euphemistically.

The Swift team probably also agonized over syntax decisions and they came up with something very different which has won over many people and attracted little criticism.

Re:Comparing Parallel Rust and C++ by pcwalton on Thursday November 07, 2019 @11:01AM (#21474335)
The only concrete thing I've seen brought up so far is that some people don't like the keyword "fn". Swift chose "func". Is there really a huge difference? (I prefer "fn", by the way.)

Swift also doesn't have pervasive use of lifetimes like Rust does. Lifetimes, by their nature, always add some level of "noise".

Re:Comparing Parallel Rust and C++ by blub on Thursday November 07, 2019 @11:50AM (#21474826)
When people do make an effort and outline pain points, those are waved away by Rust programmers or deflected by claiming that they like said syntax choice.

At the end of the day though, these tiny thing like fn, or the lifetime annotations and the many others add up to an unpleasant experience and less readable code.

Re:Comparing Parallel Rust and C++ by pcwalton on Thursday November 07, 2019 @12:41PM (#21475305)
If Rust were an unpleasant experience, it wouldn't have users. I'm sorry that you disagree with the syntax decisions. We can't please everybody.
Re:Comparing Parallel Rust and C++ by blub on Thursday November 07, 2019 @02:33PM (#21476498)
I'm not an extremist, the language clearly has certain advantages. At the same time I do believe it could have a lot more users if it were a more pleasant experience.

If it becomes a mainstream language (like Java, C++, etc), I'd be happy to concede I was wrong. It could be that memory safety will trump ergonomics and it wouldn't be the first time that somewhat painful to use tools become very popular - see Linux, git, etc.

Re:Comparing Parallel Rust and C++ by rat9988 on Thursday November 07, 2019 @12:18PM (#21475074)
Lifetime annotations are an other ugly unreadable quirk. I'm happy to know I'm not the only one.
Re:Comparing Parallel Rust and C++ by pcwalton on Thursday November 07, 2019 @12:38PM (#21475264)
Those aren't syntax though. Without lifetimes you don't have memory safety without GC. There are plenty of languages that don't have memory safety, and plenty of languages with GC, but they don't broadly share Rust's goals.
Re:Comparing Parallel Rust and C++ by rat9988 on Friday November 08, 2019 @07:08AM (#21481529)
The problem is not lifetime but its annotation.
Re:Comparing Parallel Rust and C++ by rezeroed on Thursday November 07, 2019 @02:25PM (#21476430)
fn is great. I'm not at all mathematical as suggested by others. When I go back to Go I find myself wondering why I have to type the extra two characters.
Re:Comparing Parallel Rust and C++ by FpUser on Thursday November 07, 2019 @11:07AM (#21474422)
I would very much prefer function over fn , just for plain readability . Of course it is subjective but whatever.
Re:Comparing Parallel Rust and C++ by gpderetta on Thursday November 07, 2019 @04:39PM (#21477589)
Strupstup law is relevant here:

"For new features, people insist on LOUD explicit syntax. For established features, people want terse notation."

fn is fine.

Re:Comparing Parallel Rust and C++ by rezeroed on Thursday November 07, 2019 @02:28PM (#21476455)
fn usually appears at the start of a line following an empty line - how is it not readable? I honestly think even fn serves little purpose, other than compiler parsing. New paragraph == new function.
Re:Comparing Parallel Rust and C++ by FpUser on Thursday November 07, 2019 @06:30PM (#21478507)
Whatever tickles your fancy. To each their own
Re:Comparing Parallel Rust and C++ by leotaku on Thursday November 07, 2019 @11:12AM (#21474464)
I personally much prefer the smaller "fn" to "function". I started learning programming with python's "def", so maybe it comes from that.
Re:Comparing Parallel Rust and C++ by rat9988 on Thursday November 07, 2019 @12:15PM (#21475051)
def is way better than fn. you can read def at least.
Re:Comparing Parallel Rust and C++ by kbenson on Thursday November 07, 2019 @05:23PM (#21477953)
Read def? What the point of that? You might say "def" when you see it, but you think of the concept of a function. You should be translating fn to "function" in your head or if you speak it out loud, the same way you say "plus" when you see +. How do you "read" + otherwise? It's the same for every mathematical symbol, since there is no actual way to read them, since they communicate a concept that you most likely translate into your own language in your head.
Re:Comparing Parallel Rust and C++ by lenkite on Friday November 08, 2019 @08:40AM (#21482035)
Previous poster has a small point. Even I am guilty of saying 'f-n' when reading rust code alound. Kotlin is the best - all functions are fun
Re:Comparing Parallel Rust and C++ by saghm on Thursday November 07, 2019 @12:40PM (#21475293)
I'm not convinced that the C++ way is better here; either `fn` or `function` makes it clear that you're looking at a function (and incidentally makes it very easy to search for a function with a given name in a file), whereas just having the return type and then the function name makes it ambiguous until you read further whether you're looking at a variable or a function. If I see `fn size`, I know I'm looking at a function before I get to the parentheses, but if I see `int size`, that's still ambiguous until you go a character further.
Re:Comparing Parallel Rust and C++ by boring_twenties on Friday November 08, 2019 @01:41PM (#21485327)
Unfortunately, one character further is not enough to disambiguate the C++ syntax:

    int size();
Am I declaring a function returning an int? Or defining an object of type int and invoking the default constructor?
Re:Comparing Parallel Rust and C++ by bschwindHN on Thursday November 07, 2019 @04:56PM (#21477736)
fn vs. function is probably the least of your concerns when reading and writing rust. Lifetimes, generic parameters, and complex where clauses are what will throw you.

But if you spend enough time with the language it gets easy enough for these to not be a concern. I personally think it's very much worth learning.