Live data from Hacker News

Matt Godbolt sold me on Rust by showing me C++

collabora.com

451–460 of 675 posts

Re: Matt Godbolt sold me on Rust by showing me C++

#451

Earlier quoted context omitted.

> I grew up with all the classic 8 bit micros Meaning that all the machines I've ever cared about have had 8 bit bytes. The TI-99/4A, TRS-80, Commodore 64 and 128, Tandy 1000 8088, Apple ][, Macintosh Classic, etc. Many were launched in the late 70s. By 1985 we were well into the era of PC compatibles.

in 1985 PC compatibles were talked about, but systems like VAX, and mainframes were still very common and considered the real computers while PCs were toys for executives. PCs had already shown enough value (via word processors and spreadsheets) that everyone knew they were not going away. PCs lacked things like multi-tasking that even then "real" computers had for decades.

> in 1985 PC compatibles were talked about

My https://en.wikipedia.org/wiki/Tandy_1000 came out in 1984. And it was a relatively late entry to the market, it was near peak 8088 with what was considered high end graphics and sound for the day, far better than the IBM PC which debuted in 1981 and only lasted until 1987.

Re: Matt Godbolt sold me on Rust by showing me C++

#452

Earlier quoted context omitted.

> The one thing that sold me on Rust (going from C++) was that there is a single way errors are propagated: the Result type. No need to bother with exceptions This isn't really true since Rust has panics. It would be nice to have out-of-the-box support for a "no panics" subset of Rust, which would also make it easier to properly support linear (no auto-drop) types.

This is already a thing, I do this right now. You configure the linter to forbid panics, unwraps, and even arithmetic side effects at compile time. You can configure your lints in your workspace-level Cargo.toml (the folder of crates) “”” [workspace.lints.clippy] pedantic = { level = "warn", priority = -1 } # arithmetic_side_effects = "deny" unwrap_used = "deny" expect_used = "deny" panic = "deny" “”” then in your cr…

Indent by 4 spaces to get code blocks on HN.

    Like
    this

Re: Matt Godbolt sold me on Rust by showing me C++

#454
post #48

Earlier quoted context omitted.

`panic` isn’t really an error that you have to (or can) handle, it’s for unrecoverable errors. Sort of like C++ assertions. Also there is the no_panic crate, which uses macros to require the compiler to prove that a given function cannot panic.

You can handle panics. It’s for unrecoverable errors, but internally it does stack unwinding by default like exceptions in C++. You see this whenever you use cargo test. If a single test panics, it doesn’t abort the whole program. The panic is “caught”. It still runs all the other tests and reports the failure.

> but internally it does stack unwinding by default

Although as a library vendor, you kind have to assume your library could be compiled into an app configured with panic=abort, in which case it will not do that

Re: Matt Godbolt sold me on Rust by showing me C++

#455
post #399

Earlier quoted context omitted.

My current project is a huge C++ physics sim written over 15+ years. The most common and difficult to diagnose bug I’ve found is unit conversation mistakes. We likely wouldn’t even find them if we didn’t have concrete data to compare against.

There are a few unit library in C++. Type checking in compile time is do-able with templates, even better with constexpr. The problem is, of course, each library have its own set of rules and they won't interop with each other.

I wrote such a type library myself, and it worked great. However we eventually realized it was the wrong answer because you so commonly want to display that thing and nobody wanted to write each widget to have a different api for each other the thousands of different types in my library.

The current system is a runtime system which has one type, and you set what the unit system is in the constructor. However it means adding a meter to a gallon is a runtime error.

Re: Matt Godbolt sold me on Rust by showing me C++

#456

All this has been known in the PL design community for decades if not half a century by now. Two things are incredibly frustrating when it comes to safety in software engineering: 1. The arrogance that "practitioners" have against "theorists" (everyone with a PhD in programming languages) 2. The slowness of the adoption of well-tested and thoroughly researched language concepts (think of Haskell type classes, aka, Ru…

Yep, this article is a good example of one way that c++ is bad, but it's not really a great example of rust being particularly good; many other languages support this well. I'm very glad Rust is one of those languages though!

Re: Matt Godbolt sold me on Rust by showing me C++

#457
post #308
post #261

Earlier quoted context omitted.

JeanHeyd's side of the RustConf thing: https://thephd.dev/i-am-no-longer-speaking-at-rustconf-2023

To be clear, everyone in Rust community (on Reddit, Twitter, etc) was shocked by this, and people started asking for explanations. This led to several people stepping down, and seems to have been miscommunication between Rust Foundation and Rust Project.

I'd like to read the other sides of the story; do you have any recommendations?

On the surface it sounds like a community with such deep pathology that it will take at least a generation following a complete change of leadership to have a chance at recovery. But there are three sides to every story.

Re: Matt Godbolt sold me on Rust by showing me C++

#458
post #357

Earlier quoted context omitted.

Sure, but it is pragmatic in other ways as well :) It takes ADT, but not function currying, and so on.

I don't think currying is that big a deal, it's just syntactic sugar that might or might not make things easier to read, unlike ADTs or closures which are important core concepts. I'd love to have a syntax like { foo(%1, bar) } standing for |x| { foo(x, bar) } though. I'm not aware of any language that has this!

C++ has this[1], kind of, but please don't actually use it.

> for_each(a.begin(), a.end(), std::cout Also, Scala has something similar as a first class feature[2].

[1]: https://www.boost.org/doc/libs/1_88_0/doc/html/lambda.html

[2]: https://scala-lang.org/files/archive/spec/3.4/06-expressions...

Re: Matt Godbolt sold me on Rust by showing me C++

#459
post #457
post #308

Earlier quoted context omitted.

To be clear, everyone in Rust community (on Reddit, Twitter, etc) was shocked by this, and people started asking for explanations. This led to several people stepping down, and seems to have been miscommunication between Rust Foundation and Rust Project.

I'd like to read the other sides of the story; do you have any recommendations? On the surface it sounds like a community with such deep pathology that it will take at least a generation following a complete change of leadership to have a chance at recovery. But there are three sides to every story.

I think the best summary is this: https://fasterthanli.me/articles/the-rustconf-keynote-fiasco...

> On the surface it sounds like a community with such deep pathology

First what sort of pathology? You're confusing community with leadership.

The community didn't want this, and leadership was doing a restructuring due to change from Foundation and Project. Welcome to OSS projects.

Second as opposed to what?

A community at the beck and call of your CEO dictator? I'm a Java dev, so all it takes for Java to die is for One Rich Asshole Called Larry Ellison to decide that they (ORACLE) are inserting two mandatory ads to be watched during each Java compiler run. Or god forbid that they will monetize Java.

Plus if I had 24/7 insight into how Oracle worked, I'd probably also be much less inclined to join Java as a new dev.

To paraphrase Tolstoy: (All perfect languages are dead;) Each imperfect language is imperfect in its own way.

Re: Matt Godbolt sold me on Rust by showing me C++

#460

Earlier quoted context omitted.

If you obscure the implementation a bit, you can change GP's example to a runtime overflow [0]. Note that by default the checks will only occur when using the unoptimized development profile. If you want your optimized release build to also have checks, you can put 'overflow-checks = true' in the '[profile.release]' section of your cargo.toml file [1]. [0]: https://play.rust-lang.org/?version=stable&mode=debug&editio…

This is bad because the program behaves different depending on build flags. What's the point of having "use unsafe addition" flag, and having it enabled by default? Rust developers made a poor choice. They should have made a special function for unchecked addition and have "+" operator always panic on overflow.

The point I'm sure was to prevent the checks from incurring runtime overhead in production. Even in release mode, the overflow will only wrap rather than trigger undefined behavior, so this won't cause memory corruption unless you are writing unsafe code that ignores the possibility of overflow.

The checks being on in the debug config means your tests and replications of bug reports will catch overflow if they occur. If you are working on some sensitive application where you can't afford logic bugs from overflows but can afford panics/crashes, you can just turn on checks in release mode.

If you are working on a library which is meant to do something sensible on overflow, you can use the wide variety of member functions such as 'wrapping_add' or 'checked_add' to control what happens on overflow regardless of build configuration.

Finally, if your application can't afford to have logic bugs from overflows and also can't panic, you can use kani [0] to prove that overflow never happens.

All in all, it seems to me like Rust supports a wide variety of use cases pretty nicely.

[0]: https://github.com/model-checking/kani

Post reply on HN