Earlier quoted context omitted.
Example docs for `foo() -> Result `: # Errors `foo` returns an error called `UnspecifiedError`, but this only happens when an anticipated bug in the implementation occurs. Since there are no known such bugs, this API never returns an error. If an error is ever returned, then that is proof that there is a bug in the implementation. This error should be rendered differently to end users to make it clear they've hit a b…
Funny that as a user of this library, I would just unwrap this, and it results in the same outcome as if library panicked.
Matt Godbolt sold me on Rust by showing me C++
621–630 of 675 posts
Re: Matt Godbolt sold me on Rust by showing me C++
#622Earlier quoted context omitted.
Example docs for `foo() -> Result `: # Errors `foo` returns an error called `UnspecifiedError`, but this only happens when an anticipated bug in the implementation occurs. Since there are no known such bugs, this API never returns an error. If an error is ever returned, then that is proof that there is a bug in the implementation. This error should be rendered differently to end users to make it clear they've hit a b…
My main issue with panics is poor interop across FFI boundaries.
Panicking should always be treated as a bug. They are assertions.
Re: Matt Godbolt sold me on Rust by showing me C++
#623Earlier quoted context omitted.
Can I interest you in some Moonbit? https://www.moonbitlang.com/blog/first-announce
With any new language, the first question one has to ask is, "what are the guarantees that it'll still be around in 5 years?".
Re: Matt Godbolt sold me on Rust by showing me C++
#624Earlier quoted context omitted.
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…
Thank you! I can try to answer your questions if they are important to you, but it will require some significant effort, so I'd like to be sure they aren't rhetorical first.
And how does it differ from the average Open-Source Project?
Re: Matt Godbolt sold me on Rust by showing me C++
#625Earlier quoted context omitted.
> but why not just enforce that as standard I don’t think people want that as standard. The whole point of using C++ tends to be because you can do whatever you need to for the sake of performance. The language is also heavily driven by firms that need extreme performance (because otherwise why not use a higher level language) There are knobs like stdlib assertions and ubsan, but that’s opt-in because there’s a cost…
There does not need to be an additional cost for this. Most users will do this: 1. Check if there is a value 2. Get the value There is nothing theoretically preventing the compiler from enforcing that step 1 happens before step 2, especially if the compiler is able to combine the control flow branch with the process of conditionally getting the value. The practical issue is that there's no way to express this in C++…
Yeah I agree that sane defaults would be nice and that things like unchecked accesses should be more explicit. Having linear types to properly enforce issues with things like use-after-move would also be awesome. I don’t know that anyone has ever accused C++ of being particularly ergonomic. Sum types and pattern matching would be awesome.
Nothing wrong with being a Rust fanboy :), I have written some (https://github.com/afnanenayet/diffsitter).
Re: Matt Godbolt sold me on Rust by showing me C++
#626Earlier quoted context omitted.
Errors are where I find zig severely lacking. They can't carry context. Like if you're parsing a JSON file and it fails, you can know that it failed but not where it failed within the file. Their solution in the standard library for cases like this was to handle printing to stderr internally, but that is incredibly hacky.
The std has diagnostics struct you can give to the json parser. Zig is manually memory managed language so it doesnt have payloads in errors for a good reason.
I actually find Zig quite a pleasant language other than my gripe with not handling more complex errors as cleanly.
Re: Matt Godbolt sold me on Rust by showing me C++
#627Earlier quoted context omitted.
Maybe. But I wouldn't diss better languages, linters, and other tool inprovements. These systematically increase quality at very low cost. It boggles my mind that the whole industry is not falling over itself to continuously embrace better tools and technology.
The whole industry is, the C++ ecosystem is just not.
Re: Matt Godbolt sold me on Rust by showing me C++
#628Earlier quoted context omitted.
Google has been doing a very similar, but definitely somewhat uglier, thing with StatusOr and Status (as seen in absl and protobuf) for quite some time. A long time ago, there was talk about a similar concept for C++ based on exception objects in a more "standard" way that could feasibly be added to the standard library, the expected class. And... in C++23, std::expected does exist[1], and you don't need to use excep…
I had a look. In classic C++ style, if you use *x to get the ‘expected’ value, when it’s an error object (you forgot to check first and return the error), it’s undefined behaviour! Messing up error handling isn’t hard to do, so putting undefined behaviour here feels very dangerous to me, but it is the C++ way.
Every pointer dereference, array access, and even integer truncation is UB in C++. This isn't rust.
A static analyzer can and does catch these errors and others internally. Typical usage of StatusOr is via macros like ASSIGN_OR_RETURN and RETURN_IF_ERROR; actually using the * operator would definitely draw my attention in code review.
Re: Matt Godbolt sold me on Rust by showing me C++
#629The 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…
Convention-wise Go is even better. On the one hand, there is zero magic in error handling ("Errors are values" and interface type 'error' is nothing special), on the other hand it's kind of a convention (slightly enforced by linters) that functions that return errors use this type and it's the last return parameter. Nothing prevents people from doing their own way (error int codes, bool handling, Result types, etc, p…
In Rust, you can't just skip error handling. You have to proactively do something generally unwise (and highly visible!) like call .unwrap() or you have to actually handle the error condition.
Go still relies on goodwill and a good night's sleep. The Rust compiler will guard against laziness and sleep deprivation, because ultimately programming languages are about people, not the computers.
Re: Matt Godbolt sold me on Rust by showing me C++
#630The 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…
The result type is obviously insufficient for writing nontrivial programs, because nontrivial programs fail in nontrivial ways that need exceptional control flow. The result type does not work because you have to choose between immediate callers handling failures (they don't always have the context to do so because they're not aware of the context of callers higher up on the call stack) or between propagating all of…