Live data from Hacker News

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

collabora.com

531–540 of 675 posts

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

#531
post #500

Earlier quoted context omitted.

> The lack of proper C99 floating-point support, even in $CURRENTYEAR What do you mean? What's wrong with floating point numbers in C99?

I mean things like: compilers don't support the pragmas, and if the compiler can "see" constants they are often evaluated with the wrong rounding mode. I'm far from an expert but I've seen enough to know it's wrong.

Oh, I see. I didn't realize that happened.

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

#532
post #520

Earlier quoted context omitted.

> Divide by zero must be undefined behavior in any performant language. On x86 you either have a if before running the divide (which of course in some cases the compiler can optimize out, but only if it can determine the value is not zero); or you the CPU will trap into the OS - different OSes handle this in different ways, but most not in a while that makes it possible to figure out where you were and thus do someth…

Google has a odd C++ style guide that rules out a lot of useful things for their own reasons. There is no reason why make could not work with modules if someone wanted to go through the effort. The CMake people have even outlined what needs to be done. Ninja is so much nicer that you should switch anyway - I did more than 10 years ago.

I do use Ninja when I use CMake, but honestly that mostly comes down to the fact that the Makefiles generated by CMake are horrifically slow. I don't particularly love CMake, I only use it because the C++ ecosystem really has nothing better to offer. (And there's no chance I'm going to redistribute a project that can't build with the Makefile generator, at least unless and until Ninja is default.)

Anyway, the Google C++ style guide has nothing to do with why C++ modules aren't and won't be used at Google, it's because as-implemented modules are not an obvious win. They can theoretically improve performance, but they can and do also make some cases worse than before.

I don't think most organizations will adopt modules at this rate. I suspect the early adopters will wind up being the only adopters for this one.

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

#533

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.

It's pretty difficult to have no panics, because many functions allocate memory and what are they supposed to do when there is no memory left? Also many functions use addition and what is one supposed to do in case of overflow?

> what are they supposed to do when there is no memory left?

You abandon the current activity and bubble up the error to a stage where that effort can be tossed out or retried sometime later. i.e. Use the same error handling approach you would have to use for any other unreliable operation like networking.

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

#534
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!

swift has this as well

    { foo($0, bar) }

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

#535
post #417
post #8

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, functions returning bool, functions returning 0 on success, functions returning 0 on error, functions returning -1 on error, functions returning negative errno on error, functions taking optional pointer to bool to indicate error (optionally), functions taking r…

Did you ever actually program in Rust? In my experience, a lot of the code is dedicated to "correctly transforming between different Result / Error types". Much more verbose than exceptions, despite most of the time pretending they're just exceptions (i.e. the `?` operator). Why not just implement exceptions instead? (TBH I fully expect this comment to be downvoted, then Rust to implement exceptions in 10 years... So…

I've only worked in exceptions, so I can't really comprehend the book-keeping required without them. To me it's a separation of concerns: the happy path only involves happy code. The "side channel" for the unhappy path is an exception, with an exception handler at a layer of the abstraction where it's meaningful, yet happy, code. By "happy" I mean code that's simply the direct practical work that's trying to accomplished something, so doesn't need to worry about when things go terribly wrong.

Being blind to the alternative, and mostly authoring lower level libraries, what's the benefit of not having exceptions? I understand how they're completely inappropriate for an OS, a realtime system, etc, but what about the rest? Or is that the problem: once you have the concept, you've polluted everything?

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

#536
post #464

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…

If the practitioners haven’t adopted what you’re offering for 50+ years, that thing can’t be good. Rust is also struggling with its “too theoretical” concepts by the way. The attempts of the community to gaslight the practitioners that the concepts are in fact easy to learn and straightforward are only enjoying mild success, if I may call it that.

> If the practitioners haven’t adopted what you’re offering for 50+ years, that thing can’t be good.

I wouldn't trust opinion of practitioners. Not after they have chosen javascript and, God forbid, PHP. Practitioners choose not what is inherently good, but what is popular. It is a very practical choice that brings a lot of benefits, so it is just practitioners being practitioners. It can be good or bad, I don't care now, it doesn't matter for my argument. The issue that a good thing can be overlooked by practitioners for decades, because there is nothing popular giving them this thing.

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

#537
post #511
post #464

Earlier quoted context omitted.

If the practitioners haven’t adopted what you’re offering for 50+ years, that thing can’t be good. Rust is also struggling with its “too theoretical” concepts by the way. The attempts of the community to gaslight the practitioners that the concepts are in fact easy to learn and straightforward are only enjoying mild success, if I may call it that.

”If the practitioners haven’t adopted what you’re offering for 50+ years, that thing can’t be good.” I don’t think what features are popular in C++ is good indication of anything. The language is good only due to the insane amounts of investment to the ecosystem, not because of the language features due to design. For an industrial language inventory of ”nice features to have” F# and C# are mostly my personal gold st…

The GoF book uses Smalltalk for the examples as well as C++, and Smalltalk is about the most expressive imperative language you could ask for.

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

#538

Earlier quoted context omitted.

Cool that you're using areas/pools for lifetimes. Are you also using custom data structures or stl (out of curiosity)?

Nothing fancy, I found that one can do almost anything with std::vector, a good enough hash map and a simple hand-rolled intrusive list.

std::vector is the only STL container that makes sense to use in practice.

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

#539
post #536
post #464

Earlier quoted context omitted.

If the practitioners haven’t adopted what you’re offering for 50+ years, that thing can’t be good. Rust is also struggling with its “too theoretical” concepts by the way. The attempts of the community to gaslight the practitioners that the concepts are in fact easy to learn and straightforward are only enjoying mild success, if I may call it that.

> If the practitioners haven’t adopted what you’re offering for 50+ years, that thing can’t be good. I wouldn't trust opinion of practitioners. Not after they have chosen javascript and, God forbid, PHP. Practitioners choose not what is inherently good, but what is popular. It is a very practical choice that brings a lot of benefits, so it is just practitioners being practitioners. It can be good or bad, I don't care…

But being popular can be very important for practitioners. How else are you going to hire other practitioners?

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

#540

Earlier quoted context omitted.

Eh, maybe. There's a performance tradeoff here and maintainers opted for performance. I'm sure many folks would agree with you that it was the wrong choice, and I'm sure many folks would disagree with you that it was the wrong choice. There are also specific methods for doing *erflow-checked arithmetic if you like.

Why should there be a performance tradeoff? Because Intel CPU doesn't have add-with-overflow-check instruction, we make our languages less safe?

Actually, the x86 'ADD' instruction automagically sets the 'OF' and 'CF' flags for you for signed and unsigned overflow respectively [0]. So all you need to do to panic would be to follow that with an 'JO' or 'JB' instruction to the panic handling code. This is about as efficient as you could ask for, but a large sequence of arithmetic operations is still going to gum up the branch predictor, resulting in more pipeline stalls.

[0]: https://www.felixcloutier.com/x86/add

Post reply on HN