Live data from Hacker News

A half-hour to learn Rust

fasterthanli.me

301–310 of 342 posts

Re: A half-hour to learn Rust

#301
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…

Well to be fair the 2020 end of life date was announced almost a decade ago. That said, I know that fortune 500 companies that used 2.7 to develop new code in 2017 -- which was a mistake -- mostly because they were tied to old version of RHEL and they were too lazy to try to get Python 3 to work on an old version of RHEL.

So 2020 rolled around and the pypi libraries they were using were no longer supported even though RHEL would support python 2.7. So yeah, it was a really bad experience for everyone involved.

Re: A half-hour to learn Rust

#303

Earlier quoted context omitted.

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 >`

I think you need .name("min")?.as_str() to access the underlying text of the match object (after making sure it is a valid match with the ?), which can then be parsed. The regex Match object itself does not have a parse method that I can see.

I don't know what the structure Input looks like but I played around with your code and it seems to work with as_str()

https://play.rust-lang.org/?version=stable&mode=debug&editio...

Re: A half-hour to learn Rust

#304
post #253

Earlier quoted context omitted.

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.

Maybe there will be a company like Red Hat that announces to support python 2.7 indefinitely, although I doubt it.

Re: A half-hour to learn Rust

#305
post #246

Newbie question: in the last example: fn make_tester(answer: &str) -> impl Fn(&str) -> bool + '_ { move |challenge| { challenge == answer } } why is there `move` needed, if both `answer`, and the arg of `Fn`, seem to be references (`&str`)? To a layman, this sounds like as if both "challenge" and "answer" should be borrowed - so why "move"? what's even to move here?

This is confusing, and Rust's error messages make it much worse. If you try to remove the `move`, you get an error: > closure may outlive the current function, but it borrows `answer`, which is owned by the current function. To force the closure to take ownership of `answer` use the `move` keyword. But 'answer' is of course not owned by the current function, and how can you take ownership through a shared reference?…

> But 'answer' is of course not owned by the current function

As you imply later, ‘answer’ itself is owned by the current function, but the ‘answer’ value is a pointer that doesn’t own what it points to. This subtlety, that references are full values themselves, is definitely something to trip on, especially when double indirection starts popping up like this.

Re: A half-hour to learn Rust

#306

Earlier quoted context omitted.

This is a memory leak in a GC language as well, depending on what happens to foo in ...code that uses foo... Maybe it will become a field of some class, maybe it will get pushed to some queue, maybe it will get captured in a lambda, etc. You won't even be able to tell just from looking at this code in this one place alone, if you passed this pointer as argument to a function. It is my experience that when people work…

Per Wikipedia: > In computer science, a memory leak is a type of resource leak that occurs when a computer program incorrectly manages memory allocations in a way that memory which is no longer needed is not released. In most of your scenarios, e.g. "pushed to some queue", the object in question is still needed. Hence, this is not a leak. Presumably, the entry will eventually be removed from the queue, and GC will th…

Are there any languages that provides memory leak safety, so that the compiled binary is guaranteed to be memory leak free?

Re: A half-hour to learn Rust

#307
post #283

Earlier quoted context omitted.

Typical condescending HN response. We are using Rust, we've used it to build and ship a successful native desktop app.

In which sentence is this condesdending?

The assumption that real-world use had not been tried.

Re: A half-hour to learn Rust

#308

Earlier quoted context omitted.

Bignum arithmetic actually is pretty simple in Rust if you use the right library. Rug[0] makes using bignums look almost just like using native numbers through operator overloading. [0] https://crates.io/crates/rug

The operator overloading is nice but you still get smacked in the face right away by the borrow checker. Simple stuff like this won't compile ("use of moved value"): let a = Integer::from(10); let b = a + a;

This would work if `Integer` would implement the `Copy` trait. But I guess that type is heavy enough for it to be too expensive, therefore forcing you to explicitly call `clone()`.

Re: A half-hour to learn Rust

#309
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 know it’s pedantic but I despise the semicolons in Rust. They make the language ugly and constantly burden the programmer unnecessarily. It’s a bizarre choice for such a modern language.

Re: A half-hour to learn Rust

#310
post #308

Earlier quoted context omitted.

The operator overloading is nice but you still get smacked in the face right away by the borrow checker. Simple stuff like this won't compile ("use of moved value"): let a = Integer::from(10); let b = a + a;

This would work if `Integer` would implement the `Copy` trait. But I guess that type is heavy enough for it to be too expensive, therefore forcing you to explicitly call `clone()`.

That `Integer` type can't implement `Copy` because it manages a resource, meaning you can't just do a simple memcpy of the type.
Post reply on HN