News for hackers. Stuff that matters.
Re:Rust can be difficult to learn and frustrating, but it's ... by dbcurtis on Monday October 22, 2018 @11:22PM (#18280494)
> Rust is the answer to the question "can we have speed, correctness, and expressiveness in one language?"

My biggest gripe is that they left out readability.

I like the semantics of Rust, and appreciate the performance and the transparent memory model. I am extremely excited to try Rust on an embedded project.

Bur honestly, the syntax is gruesome. Coming from Python, Rust looks like two rabid gerbils had a war dance on my keyboard.

Re:Rust can be difficult to learn and frustrating, but it's ... by carlmr on Tuesday October 23, 2018 @03:15AM (#18281374)
>Bur honestly, the syntax is gruesome. Coming from Python, Rust looks like two rabid gerbils had a war dance on my keyboard.

What exactly is terrible about it? The snake_case I got used to, I kind of like having braces, and that's not really a killer argument either, because most languages have them, apart from that I find Rust also much cleaner than Python syntax. I'm really not sure what you mean. Is it the lifetime annotations (because they're somewhat necessary).

Re:Rust can be difficult to learn and frustrating, but it's ... by iopq on Tuesday October 23, 2018 @04:36AM (#18281747)
Okay, tell me if this is readable to you:

   fn accumulate<'a, T: Monoid>(tuples: &[(&'a str, &Fn(i32) -> bool)], i: i32) -> T
   where
        T: From<&'a str> + From<String>,
this is JUST the function signature

yes, every single thing in there is necessary, it can be written in a more gruesome way, but the where clause clarifies it a bit

But let me cheat a little bit

    ( $(#[$attr:meta])* enum $enumer:ident { $($i:ident => $e:tt $( ( $($m:ident),* ) )* ; )* } ) => {
how is this macro syntax looking?
Re:Rust can be difficult to learn and frustrating, but it's ... by carlmr on Tuesday October 23, 2018 @04:44AM (#18281777)
#1 I find is not worse than C++, granted there's more complexity here than in Python but in terms of cleanness its ok IMHO. Because as you said there's nothing unnecessary. Rust addresses different problems than Python, so we should compare apples with apples.

On the second one you got me though, I find the macro syntax a bit horrible. Sometimes I just want simple text substitution.

Re:Rust can be difficult to learn and frustrating, but it's ... by iopq on Tuesday October 23, 2018 @06:24AM (#18282180)
I'm comparing it to Haskell syntax for the same thing, which is much cleaner
Re:Rust can be difficult to learn and frustrating, but it's ... by olavk on Tuesday October 23, 2018 @06:47AM (#18282269)
Haskell does not have borrowing and lifetime specifiers though, which is what makes the Rust example more dense.
Re:Rust can be difficult to learn and frustrating, but it's ... by iopq on Tuesday October 23, 2018 @11:02AM (#18283941)
Haskell has nice syntax for generics, no stupid <> to forward declare type parameters
Re:Rust can be difficult to learn and frustrating, but it's ... by User23 on Tuesday October 23, 2018 @06:44AM (#18282256)
C++ templates also aren't winning any readability awards.
Re:Rust can be difficult to learn and frustrating, but it's ... by olavk on Tuesday October 23, 2018 @06:46AM (#18282264)
It is somewhat unfair to compare this to Python, since a lot of the simplicity in Python comes from the semantics (dynamically typed, garbage collected and so on). Rust need to express all this information (types, lifetimes etc.), so it will necessarily be more dense. The question is if this information could be expressed in a more readable syntax. This might be possible, but I would like to see a suggestion of how.

I guess the signature could be made more readable by using a few type aliases. The hardest part to read is the nested types.

I'm with you on the macro syntax, it is very hard to read. It is not easy to create a readable macro syntax though. All languages I know have hard-to-read macros, so this is not yet a solved problem.

Re:Rust can be difficult to learn and frustrating, but it's ... by iopq on Tuesday October 23, 2018 @11:17AM (#18284068)
Here is a simpler syntax:

   fn accumulate tuples: &[(&'a Str, &Fn(i32) -> Bool)], i: i32 -> t
   where
        t: Monoid + From &'a Str + From String,
this is how Haskell with lifetimes and borrowing would look like (if arguments were not curried)
Re:Rust can be difficult to learn and frustrating, but it's ... by Rusky on Tuesday October 23, 2018 @07:46PM (#18288484)
This is arguably less readable, because it's missing some delimiters for your eyes to latch onto.

It's also not realistically parseable- the Haskell/Ocaml-like removal of <>s and ()s relies on application being left-associative, and if you read this under that rule you've changed the meaning (e.g. `From &'a Str`).

Re:Rust can be difficult to learn and frustrating, but it's ... by olavk on Wednesday October 24, 2018 @06:31AM (#18291153)
I like removing superfluous punctuation, but if parentheses are removed from method signatures than they should also be removed from invocations, which in turn comes with its own set of readability issues. I'm not a fan of the $ operator in Haskell, for example.
Re:Rust can be difficult to learn and frustrating, but it's ... by antaviana on Tuesday October 23, 2018 @09:02AM (#18282965)
This also reminds me that, in Python 2.x, the following code...

for i in range(100000000):

...creates in memory a list with one-hundred million integers.

Expressive yes, but sometimes it can be double-edged for new comers (and not new comers).

Re:Rust can be difficult to learn and frustrating, but it's ... by nchie on Tuesday October 23, 2018 @04:06AM (#18281600)
As someone with a C++ background who loves Rust and wants it to succeed: Code where the lifetime syntax is used much can look really horrible and confusing, and to people new to Rust it might feel like it's for no reason.
Re:Rust can be difficult to learn and frustrating, but it's ... by village-idiot on Monday October 22, 2018 @11:48PM (#18280597)
Python is pretty to look at, but I hate working in white space sensitive languages. If I have to have another argument about tabs vs. spaces I am going to toss my monitor out the frickin’ window.

Also, it makes autoindent in Emacs worse.

Re:Rust can be difficult to learn and frustrating, but it's ... by dbcurtis on Tuesday October 23, 2018 @12:51AM (#18280802)
Well, tabs versus spaces is not a Python thing, that will bite you in any language eventually. Blame the VT-100 terminal.

Here is the thing about indentation versus curly-braces-and-semi-colons: It boggles me that people find it acceptable to use one mechanism to communicate block structure to the compiler, and a completely different mechanism to communicate block structure to humans, and have no way to automatically check that they have the same semantics. This is a frequent source of bugs, and is entirely preventable. When it comes to the ergonomics of computer-convenient versus human-convenient, humans should win. Therefore, significant white space is clearly preferable simply from the standpoint of eliminating the source of an entire class of bugs.

But the main thing that makes Rust harder to read is all the punctuation noise and short, cryptic keywords. While one friend once said: "A good programmer can write FORTRAN in any language.", I don't feel compelled to help them.

Readability matters.

Re:Rust can be difficult to learn and frustrating, but it's ... by Tuna-Fish on Tuesday October 23, 2018 @04:31AM (#18281722)
> It boggles me that people find it acceptable to use one mechanism to communicate block structure to the compiler, and a completely different mechanism to communicate block structure to humans, and have no way to automatically check that they have the same semantics. This is a frequent source of bugs, and is entirely preventable.

Strongly agree. The solution that Rust, Go and other new languages have adopted is shipping a formatting tool to consistently make the semantics of indentation and braces match. I personally can't help but think that this is a worse-is-better solution when compared to significant whitespace, but at least it works. Every Rust CI I am setting up will fail the build if `rustfmt --write-mode=diff` feels like you didn't run rustfmt before committing.

> But the main thing that makes Rust harder to read is all the punctuation noise

Given the decision to favor explicit casts, references and dereferences over implicit ones, this cannot really be helped. In some ways, once you get used to it, it helps readability, because it always communicates what the things being worked on are.

> and short, cryptic keywords.

I agree that this was probably a mistake. Cannot really be helped now, though.

Overall, I think the readability argument against Rust is overstated. Sure, when you are starting out it looks like line noise, especially if compared to python. But it didn't take me more than a week or two before it basically became entirely clear and readable. The radical explicitness of the language helps readability in many ways that make it much better than C++.

Of course, much better than C++ is a low bar to pass.

Re:Rust can be difficult to learn and frustrating, but it's ... by village-idiot on Tuesday October 23, 2018 @08:14AM (#18282666)
I think Go shipping a single canonical formatting tool was an inspired decision that eliminates a massive point of contention in software teams. I expect the majority of new languages to ship a canonical format tool in the future.
Re:Rust can be difficult to learn and frustrating, but it's ... by jononor on Tuesday October 23, 2018 @04:17AM (#18281653)
GCC will now warn about (some cases of) misleading indentation, which is a step forward. And clang format can autoformat based on the brackets, I believe.

I still prefer whitespace to indicate blocks though.

Re:Rust can be difficult to learn and frustrating, but it's ... by ernst_klim on Tuesday October 23, 2018 @06:12AM (#18282139)
>Python is pretty to look at

Python is ugly and inconsistent as hell due to lack of methods (no maps or reduce in collections for example), indentation, lack of expressions (nearly everything is a statement) and one statement lambdas.

Though rust is beyond good and evil indeed, I really don't get this obsession with brackets and C-like abominations like &*staff. Ada or SML are doing a much better job.

Re:Rust can be difficult to learn and frustrating, but it's ... by olavk on Tuesday October 23, 2018 @02:31AM (#18281172)
PEP-8 (more than 15 years old) recommend spaces, so unless you are deliberately looking for a fight, the question is settled.

Autoindent is a solution to a problem that doesn't exist in Python in the first place. Having two independent representations for blocks, one for human readers (indent) and one for compilers (braces), leads to nasty bugs when they get out of sync. Autoindent is a tool to keep them in sync. In Python there is a single representation, so nothing can get out of sync.

Re:Rust can be difficult to learn and frustrating, but it's ... by namibj on Tuesday October 23, 2018 @05:09AM (#18281888)
But the tooling for editing the code has no support for indenting blocks as trivially as adding braces. Sure, you just run clang-format or such on the block/file, and get all the visual stuff sorted out.
Re:Rust can be difficult to learn and frustrating, but it's ... by olavk on Tuesday October 23, 2018 @06:17AM (#18282160)
What editor does not support indenting a block? In most editors I know you select the block and hit tab, or shift-tab to outdent.
Re:Rust can be difficult to learn and frustrating, but it's ... by namibj on Tuesday October 23, 2018 @10:05PM (#18289119)
The difference is that I can add braces in the middle of multiple lines, just need to get my changes to match up, and then I can tell it to reformat the changed section/the whole file. For block indenting, I have to select each block I want to operate on before issuing the block indent command. Braces let me skip the selecting, requiring the same cursor movement but allowing batch insertion of selection begin/end markers, in a sense.
Re:Rust can be difficult to learn and frustrating, but it's ... by village-idiot on Tuesday October 23, 2018 @08:15AM (#18282668)
Or reformat the entire file according to global formatting styles, like IntelliJ.
Re:Rust can be difficult to learn and frustrating, but it's ... by bb88 on Tuesday October 23, 2018 @12:35AM (#18280745)
Wait, let me get under your window...

> If I have to have another argument about tabs vs. spaces I am going to toss my monitor out the frickin’ window.

Clearly the correct answer is spaces. /s

Seriously though, I like python because not only is it pretty, it's also concise. While it's not perfect, a lot of time has been spent on language features to make them easily comprehendable.

The lesson for me from python is that UX is important, even in programming languages.

Re:Rust can be difficult to learn and frustrating, but it's ... by Rotareti on Tuesday October 23, 2018 @01:38AM (#18280964)
> I hate working in white space sensitive languages.

I think it's funny how people still have issues with this in 2018.

Re:Rust can be difficult to learn and frustrating, but it's ... by emmelaich on Tuesday October 23, 2018 @05:29AM (#18281957)
There is no such thing as white space insensitive language.
Re:Rust can be difficult to learn and frustrating, but it's ... by kbob on Tuesday October 23, 2018 @02:52PM (#18286289)
Fortran IV came close. You could put spaces in the middle of identifiers, keywords, and numbers, and the compiler ignored them. The language did not require spaces as separators anywhere. Spaces were only significant in Hollerith constants (what we'd call string literals today) and in columns 1-6. Columns 1-6 were reserved for line numbers, comment signifiers, and continuation marks.
Re:Rust can be difficult to learn and frustrating, but it's ... by emmelaich on Tuesday October 23, 2018 @09:05PM (#18288855)
Indeed, the classic resulting bug was the do loop with a typo. Instead of comma the program had a period. So this

   DO I = 1.100
was interpreted as assignment

   DOI = 1.1

Though contrary to urban legend it did not result in the loss of any rockets.

   http://catless.ncl.ac.uk/Risks/9.54.html#subj1
Re:Rust can be difficult to learn and frustrating, but it's ... by village-idiot on Tuesday October 23, 2018 @08:16AM (#18282679)
Aside from strings, isn’t C white space insensitive?
Re:Rust can be difficult to learn and frustrating, but it's ... by kbob on Tuesday October 23, 2018 @02:54PM (#18286305)

    intmain()
    {
        r etu rn0;
    }
Re:Rust can be difficult to learn and frustrating, but it's ... by majewsky on Tuesday October 23, 2018 @05:20PM (#18287603)
The tokenizer is. `ab` is different from `a b`.
Re:Rust can be difficult to learn and frustrating, but it's ... by ilovecaching on Monday October 22, 2018 @11:26PM (#18280512)
Well... compared to Python is kind of an apples to oranges comparison. Compared to Java or C++ I find it to be incredibly direct and expressive. Rust definitely doesn't stop you from writing spaghetti, but no language does.
Re:Rust can be difficult to learn and frustrating, but it's ... by petersellers on Tuesday October 23, 2018 @01:09AM (#18280860)
I don't think the potential for spaghetti code is the problem, I think it's more the terseness of Rust code that makes it hard to read (speaking as someone who doesn't know Rust very well, but has a mild interest in learning it). I agree with the above complaint - it does feel a bit terse and that makes it harder to read IMO.

Languages like Java are more verbose which does make it a bit more frustrating to write but on the flip side I find them easier to read.

Re:Rust can be difficult to learn and frustrating, but it's ... by namibj on Tuesday October 23, 2018 @05:11AM (#18281894)
That's in part due to the compiler not yet being the best in type inference, and should get better (as far as explicit type signatures are required).