Live data from Hacker News

Rust 1.45

blog.rust-lang.org

101–110 of 227 posts

Re: Rust 1.45

#101
post #67

If you have been on the fence about learning Rust, I encourage you to dive in. It is very productive.

How is the build system? Is it stable and easy?

stable: depends on what you mean, but afaict, cargo is very stable, in both terms of interface and bugfree-ness.

easy: far easier than gradle and maven, imho even easier than go. Definitely easier than cmake.

Re: Rust 1.45

#102

Earlier quoted context omitted.

I thing you are right about that, I'd prefer panicking too. Also, reading the RFC will surely clear up the motivation. Without knowing this case, I'd wager a guess: it's about performance. Panicking introduces a branch and side-effects which, again, affects negstively optimization potential and performance. The saturating cast affects performance too, but less. If some old code has a lot of number crunching containin…

It is't about performance because array indexing also panics.

Compilers are better at eliding array index checks than about eliding numeric overflow checks; an ordinary function that operates on arrays will often be able to reasonably determine both the length of the array and the scope of the indexing variable (Rust's iterators are very good at this), whereas an ordinary math function often has almost no information that usefully limits which values it might be getting called with.

I don't disagree that making more obvious errors into panics would be nice, but the performance implications are often quite unforgiving.

Re: Rust 1.45

#103

> Just like with array access, the compiler can often optimize the checks away, making the safe and unsafe versions equivalent when the compiler can prove it. Can it "often" solve the halting problem as well? The hope that this kind of optimization will happen sounds a bit fanciful for any non-trivial part of a program.

You would be surprised, at least with array access stuff. And, if it doesn't, you can often help it understand with a bit of work. Sometimes an assert before a loop or re-slicing something can take a check in the body of a loop and move it out to a single one.

I ported a small C function to Rust recently that involved some looping, and all of the bounds checking was completely eliminated, even once I took the line-by-line port and turned it into a slightly higher level one with slices and iterators instead of pointer + length.

Re: Rust 1.45

#104

Earlier quoted context omitted.

Rust has no specification.

Sort of; we have more than nothing, but not a full thing. Some things are well specified. Some things are mostly specified. Some things are still very much up in the air.

Do you have specification of a memory model?

Re: Rust 1.45

#105

Earlier quoted context omitted.

Fortran predictably overflows the result, in contrast to fptoui which gives a poison value. I agree that even a predictable overflow can bite you on the behind. But it's better than undefined behavior. I'm not a fan of saturated cast, but having a defined behavior is for sure a great improvement.

When working with audio as an example, saturation is much less obnoxious than wraparound. You can potentially destroy speakers and your hearing that way.

Saturated addition is indeed the correct way to add two PCM streams together.

Especially back in the 1980s and 1990s you'd get awful code that did things like averaging the two streams because wrapping sounds awful and the authors were ignorant of the theory and/or unaware that saturated addition is a thing.

You can tell when somebody did this because it means playing silence makes everything else quieter, or worse there's an arbitrary limit on how many streams are played and playing any one thing is very quiet because it's attenuated so as to never wrap.

Haiku the 1990s-style operating system did this for years, as did various Amiga music software.

Re: Rust 1.45

#106
post #34
post #14

By any chance if anyone is in the Paris area and is interested to teach Rust at university next year during the first semester. Please get in touch :).

Is this undergrad? Genuinely curious, how will you get someone to understand what ownership helps avoid without them having experienced the pain on the other side? I guess with younger and younger kids learning programming these, may be there can handle more? I am not sure if my son would understand all of the intricacies in his first semester.

One section of CS3210 Design of Operating Systems at Georgia Tech in the Spring was experimentally using Rust[0]. I'd never used it before, but by that point I had a decent amount of experience with C from previous classes. I personally didn't struggle with the borrow checker too much, because I did have some experience with what happens when there isn't ownership. I took another C and C++ heavy course at the same time (CS4290) and wished I could use Rust, since most of my trouble with projects came down to debugging pointers not being in the right place. I'm in the Systems concentration though, so I don't know how people only experienced in, for lack of a better term, higher-level languages would fare. Still, I think that students interested in taking a Rust class would have enough experience with other systems languages to be able to see what ownership can do for you.

Maybe the professor for this class could assign a non-trivial project in C at the start of the semester then the same project again at the end of the semester except in Rust.

[0] https://tc.gts3.org/cs3210/2020/spring/

Re: Rust 1.45

#107

I keep seeing more and more news about Rust, and figure that perhaps it is time that I learn something new. 99% of my development work these days is C with the target being Linux/ARM with a small-ish memory model. Think 64 or 128MB of DDR. Does this fit within Rust's world? I've noticed that stripped binary sizes for a simple "Hello, World!" example are significantly larger with Rust. Is this just the way things are…

I've been playing with Rust myself in my free time, and if you use Rust with the standard library a stripped executable should be smaller and more comparable to C than what you're seeing with the standard library included. Depending on your use case, you might be able to get away with just using the core library

Re: Rust 1.45

#108

Earlier quoted context omitted.

Sort of; we have more than nothing, but not a full thing. Some things are well specified. Some things are mostly specified. Some things are still very much up in the air.

Do you have specification of a memory model?

Not yet. That falls under the "underspecified, but there is active work ongoing" bit. There's a lot there.

Re: Rust 1.45

#109
post #97

Earlier quoted context omitted.

That could literally produce no output program?

Yep! Dumb example. main() x = get_from_some_external_data_source() if x: print("Hello World") trigger_ub() You might expect this code to always print if x is true but the optimizer can look at this and say "welp, if x is true then it would trigger ub, therefore it must be false, and since x must always be false we can just remove that entire branch."

My favorite example along these lines (in C) is "Cap'n'Proto remote vuln: pointer overflow check optimized away by compiler"[1] which was covered here a few years back and shows all of these "theoretical" compiler behaviors coming to a head in a real bug which is thoroughly explained.

1: https://news.ycombinator.com/item?id=14163111

Re: Rust 1.45

#110
post #67

If you have been on the fence about learning Rust, I encourage you to dive in. It is very productive.

How is the build system? Is it stable and easy?

In my experience, Cargo is much easier and more reliable than the systems I've used across Java/C++/Scala/Python/Go/JavaScript. It is such a pleasure to use.
Post reply on HN