Live data from Hacker News

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

collabora.com

1–10 of 675 posts

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

#7

What if we have a C that removes the quirks without adding too much brain drain? So no implicit type conversions, safer strings, etc.

Walter Bright will probably show up soon to plug D's BetterC mode, but if he doesn't, still check it out.

https://dlang.org/spec/betterc.html

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

#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 reference to std::error_code to set an error (and having an overload with the same name that throws an exception on error if you forget to pass the std::error_code)...I understand there's 30 years of history, but it still is annoying, that even the standard library is not consistent (or striving for consistency).

Then you top it on with `?` shortcut and the functional interface of Result and suddenly error handling becomes fun and easy to deal with, rather than just "return false" with a "TODO: figure out error handling".

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

#9
Amazing example of how easy it is to get sucked into the rust love. Really sincerely these are really annoying parts of C++.

The conversation function is more language issue. I don’t think there is a simple way of creating a rust equivalent version because C++ has implicit conversions. You could probably create a C++ style turbofish though, parse([your string]) and have it throw or return std::expected. But you would need to implement that yourself, unless there is some stdlib version I don’t know of.

Don’t conflate language features with library features.

And -Wconversion might be useful for this but I haven’t personally tried it since what Matt is describing with explicit types is the accepted best practice.

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

#10
post #5

What if we have a C that removes the quirks without adding too much brain drain? So no implicit type conversions, safer strings, etc.

This seems like such an obvious thing to have - where is it? Zig, Odin, etc. all seem much more ambitious.

There have been attempts over the years. See here, a decade ago: https://blog.regehr.org/archives/1287

> eventually I came to the depressing conclusion that there’s no way to get a group of C experts — even if they are knowledgable, intelligent, and otherwise reasonable — to agree on the Friendly C dialect. There are just too many variations, each with its own set of performance tradeoffs, for consensus to be possible.

Post reply on HN