Live data from Hacker News

Rust from a Gopher – Lessons 3 and 4

levpaul.com

21–27 of 27 posts

Re: Rust from a Gopher – Lessons 3 and 4

#21

> const MAX_POINTS: u32 = 100_000; // wtf is this ugly numeric shit Java has had this since Java7 and Go has had it since at least 1.13, so I'm not sure why he hasn't seen it based on his other experiences.

In 2001 I witnessed five Java devs (all with over a year of experience) huddled around a desk looking at a line of code like this:

  int x = foo?bar:baz;
"Question mark and colon aren't legal characters in variable names!"

"They must be. The code compiles!"

"But where is this symbol defined? How can it be in scope here?"

"The code compiles, but it doesn't work, right? It must be a compiler bug!"

That's the risk of learning a language "on the job" or from piecemeal tutorials, instead of reading a book or similar resource from start to end. Sometimes there's a corner of the language that by chance you just haven't seen yet, even after years.

Re: Rust from a Gopher – Lessons 3 and 4

#22
post #20

Btw. there are parts in the standards library which are not suited for learning rust by understanding it. Not only might your run into some but trivial edge case complexity which add the user of the standard library you don't have to know about at all but you will also run into a bunch of unstable nightly and as such often but that well documented thinks, some of which might never get stabilized. So if you start lear…

Almost every language is like this though.

Sure, I just have seen arguments like:

- go through the standard library to learn rust

- the standard library is always the stile/way you should write your own code

to often in rust related discussion. And while this is actually true for parts of the rust std, it needs to be taken with a big grain of salt.

Re: Rust from a Gopher – Lessons 3 and 4

#23

The part complaining about missing details in the error message seems weird. You get a pretty detailed error even without using `--explain`: error[E0384]: cannot assign twice to immutable variable `x` --> src/main.rs:4:5 | 3 | let x = 3; | - | | | first assignment to `x` | help: make this binding mutable: `mut x` 4 | x = 5; | ^^^^^ cannot assign twice to immutable variable error: aborting due to previous error; 2 war…

As someone who started learning Rust a few days ago I find its compiler errors incredibly helpful! I don’t quite understand the author‘s complaint either - the error message in the example (like most others) does state quite precisely what went wrong and how to fix it (By default, variables in Rust are immutable. To fix this error, add the keyword `mut` after the keyword `let` when declaring the variable.). I wonder…

Default mutability like practically every large language? I’ll admit, both have their uses, but if you’re striving for less runtime errors, default immutability makes more sense.

Re: Rust from a Gopher – Lessons 3 and 4

#24

Earlier quoted context omitted.

As someone who started learning Rust a few days ago I find its compiler errors incredibly helpful! I don’t quite understand the author‘s complaint either - the error message in the example (like most others) does state quite precisely what went wrong and how to fix it (By default, variables in Rust are immutable. To fix this error, add the keyword `mut` after the keyword `let` when declaring the variable.). I wonder…

Default mutability like practically every large language? I’ll admit, both have their uses, but if you’re striving for less runtime errors, default immutability makes more sense.

These are not runtime errors. But regardless I rather like a runtime error instead of doing the wrong thing.

Re: Rust from a Gopher – Lessons 3 and 4

#25

Earlier quoted context omitted.

Default mutability like practically every large language? I’ll admit, both have their uses, but if you’re striving for less runtime errors, default immutability makes more sense.

These are not runtime errors. But regardless I rather like a runtime error instead of doing the wrong thing.

Why would you prefer a runtime error over just not making the mistake in the first place?

Re: Rust from a Gopher – Lessons 3 and 4

#26

Earlier quoted context omitted.

These are not runtime errors. But regardless I rather like a runtime error instead of doing the wrong thing.

Why would you prefer a runtime error over just not making the mistake in the first place?

Because I don't like having bombs in my software waiting to explode when you touch it. That's essentially what mutable by default is.

Re: Rust from a Gopher – Lessons 3 and 4

#27

Earlier quoted context omitted.

Why would you prefer a runtime error over just not making the mistake in the first place?

Because I don't like having bombs in my software waiting to explode when you touch it. That's essentially what mutable by default is.

Well then we’re on the same page: default immutability is better. You’re wording three comments up seemed to say you prefer default mutability
Post reply on HN