Live data from Hacker News

A half-hour to learn Rust

fasterthanli.me

291–300 of 342 posts

Re: A half-hour to learn Rust

#291

Earlier quoted context omitted.

Fair fair. To be honest, I think in a lot of these cases there are good helper crates/macros; for this I would now probably use recap: https://docs.rs/recap/0.1.1/recap/ The really horrendous scenario was when I was trying to navigate pest iterators for parsing according to a grammar.

Even without if let or match many of those unwraps are unnecessary. See https://github.com/zookini/aoc-2020/blob/master/src/bin/2.rs

Interesting! Can you help me understand why this doesn't work for me?

    error[E0599]: no method named `parse` found for enum `Option>` in the current scope
      --> src\main.rs:24:39
       |
    24 |                 min: caps.name("min").parse().unwrap(),
       |                                       ^^^^^ method not found in `Option>`

Re: A half-hour to learn Rust

#293
post #161

As a Python programmer with limited experience with compiled languages, Rust code was more intimidating to read or look at than C++, Java or Go. After only an hour, I am overwhelmed by the sheer beauty and mature design of this language - it almost reads like Python or as well as any compiled language can. I cannot believe that I am smitten by Rust within an hour. Its features seem, obvious. My experience with Go was…

I've shipped relatively lots of code in Python and a little bit in Rust. For any project where performance or correctness are significant concerns I'd much rather use Rust than Python. It provides a lot more tools to help you write correct code, and express invariants in a machine-checkable way. This means that they are maintained when the code changes, even when multiple contributors are involved. I'm must more conf…

> For any project where performance or correctness are significant concerns I'd much rather use Rust than Python. It provides a lot more tools to help you write correct code, and express invariants in a machine-checkable way. This means that they are maintained when the code changes, even when multiple contributors are involved. I'm must more confident in my ability to ship correct code in Rust and maintain that correctness over time.

Any reason for why Rust over Ada/SPARK?

Re: A half-hour to learn Rust

#294
post #253

Earlier quoted context omitted.

My only bone to pick with this commentary is that it is 2020 and people are still complaining about Python as being unstable because of 2 -> 3. It was a rough transition, to be sure. Python2 was released 20 years ago, and Python3 12 years ago. It is a pretty stable language.

I don't think the parent is talking about Python 2 -> 3. I think they are pointing out that for many developers, moving to Python 3 happened very late. That means they ran 2.7 since 2010 (roughly 10 years now.) Now that they are on 3.x, they get issues with each new 3.x release. The argument is that being on 2.7 for so long gave a false impression of the language being more stable than it is - developers just weren't…

Some people are still using 2.7 in production.

Re: A half-hour to learn Rust

#296
It's remarkable how similar Swift and Rust are w.r.t syntax.

Rust, Swift

let x = 42; let x = 42

let x: i32 = 42; let x: Int = 42

let _ = 42; let _ = 42

let pair: (char, i32) = ('a', 17); let pair: (String, Int) = ("a", 17)

let (some_char, some_int) = ('a', 17); let (some_char, some_int) = ("a", 17)

fn greet() { println!("Hi there!"); } func greet() { print("Hi there!") }

But, the languages are so different, for instance in Swift

let x x = 42

let y = 13 let y = y + 3

Wont fly for instance. I am trying to come up with the simplest explanation possible for this but I can't - goes to show how much I understand either of the languages.

Re: A half-hour to learn Rust

#297

It's remarkable how similar Swift and Rust are w.r.t syntax. Rust, Swift let x = 42; let x = 42 let x: i32 = 42; let x: Int = 42 let _ = 42; let _ = 42 let pair: (char, i32) = ('a', 17); let pair: (String, Int) = ("a", 17) let (some_char, some_int) = ('a', 17); let (some_char, some_int) = ("a", 17) fn greet() { println!("Hi there!"); } func greet() { print("Hi there!") } But, the languages are so different, for insta…

Swift tends to be a lot more readable with fewer ambiguities.

Call me superficial but all the underscores and semicolons alone just feel like an eldritch summoning ritual in 2021.

Re: A half-hour to learn Rust

#299

Earlier quoted context omitted.

I've shipped relatively lots of code in Python and a little bit in Rust. For any project where performance or correctness are significant concerns I'd much rather use Rust than Python. It provides a lot more tools to help you write correct code, and express invariants in a machine-checkable way. This means that they are maintained when the code changes, even when multiple contributors are involved. I'm must more conf…

> For any project where performance or correctness are significant concerns I'd much rather use Rust than Python. It provides a lot more tools to help you write correct code, and express invariants in a machine-checkable way. This means that they are maintained when the code changes, even when multiple contributors are involved. I'm must more confident in my ability to ship correct code in Rust and maintain that corr…

If you have a lot of string handling the strictness and ease of safe zero copy in Rust would make it unbeatable for performance and safety.

Due to lifetimes it's easy to keep string slices as references into the original memory and if you do need to modify some strings, you can use CoW.

The way Rust deals with encoding also makes it much safer to use Rust. Since you need to be very explicit about which encoding you convert to what and if you want to allow lossy conversions.

I don't think there is much of an equivalent in ADA for this. ADA has other benefits, like the delta (fixed point) types which help a lot in embedded projects.

Re: A half-hour to learn Rust

#300

Earlier quoted context omitted.

I've shipped relatively lots of code in Python and a little bit in Rust. For any project where performance or correctness are significant concerns I'd much rather use Rust than Python. It provides a lot more tools to help you write correct code, and express invariants in a machine-checkable way. This means that they are maintained when the code changes, even when multiple contributors are involved. I'm must more conf…

> For any project where performance or correctness are significant concerns I'd much rather use Rust than Python. It provides a lot more tools to help you write correct code, and express invariants in a machine-checkable way. This means that they are maintained when the code changes, even when multiple contributors are involved. I'm must more confident in my ability to ship correct code in Rust and maintain that corr…

Ada/Spark is more about mathematically proving that your program works. Rust is more about that your program won't trample memory and won't crash.

That said, Rust seems to have reasonably good performance compared to C/C++. Also the concept of lifetimes is interesting too.

Just because your program compiles in C++/Ada(no-spark)/C/Java/Rust doesn't mean it's correct. If it compiles in Rust, the compiler is telling you it's memory safe and thread safe.

Post reply on HN