Earlier quoted context omitted.
yeah go/rust error handling is great. Much better than exceptions which make the code hard to read since you can't easily predict where is the flow going to jump. And the multiple-return is very convenient in this case too. Also, with Go's approach you have to either explicitly ignore the error or deal with it.
My problem with Go (and I love the language a lot) is that a lot of my error handling is "stop execution in the function and bubble the error up", which results in my code being littered with if err != nil { return err }, which is a bit annoying. If I'm doing something wrong here I'd love to know it.
Why should I have written ZeroMQ in C, not C++ (2012)
31–40 of 147 posts
Re: Why should I have written ZeroMQ in C, not C++ (2012)
#32Earlier quoted context omitted.
And so I will continue to avoid C++ because I'm not a master and will not avoid the many pitfals, and I want to get things done, not become a master of C++.
Good luck finding a language out there that doesn't have pitfalls.
Re: Why should I have written ZeroMQ in C, not C++ (2012)
#33This might be unrelated, but after reading this 3 years after publication I think that Go approach to error handling i so much better because of exactly the same simplicyty as C. ( If you dont’t understand why, dont’t worry it will be obvious to you in 3 years :-)
I don't like that I can't locally hide the boiler plate. There's obviously some measure of essential tension there; I could cope.
I still haven't gotten over the use of product types for return values rather than sum types, and I'm not sure if I will.
Re: Why should I have written ZeroMQ in C, not C++ (2012)
#34Earlier quoted context omitted.
yeah go/rust error handling is great. Much better than exceptions which make the code hard to read since you can't easily predict where is the flow going to jump. And the multiple-return is very convenient in this case too. Also, with Go's approach you have to either explicitly ignore the error or deal with it.
My problem with Go (and I love the language a lot) is that a lot of my error handling is "stop execution in the function and bubble the error up", which results in my code being littered with if err != nil { return err }, which is a bit annoying. If I'm doing something wrong here I'd love to know it.
- you can collect errors in a function and return them once or provide an extra method, like http://golang.org/pkg/bufio/#Scanner.Err
- you can type switch on the error; maybe there are errors that you can recover/retry locally, such as connection errors, or general io failures - so you do not need to pass back all errors to the caller
More on errors: https://blog.golang.org/errors-are-values
Re: Why should I have written ZeroMQ in C, not C++ (2012)
#35http://yosefk.com/c++fqa/exceptions.html#fqa-17.1
http://yosefk.com/c++fqa/ctors.html#fqa-10.17
http://yosefk.com/c++fqa/exceptions.html#fqa-17.3
The FQA helped my crystallize a lot of the reasons I hated C++. Even if you like C++, it's a good idea to understand the FQA's arguments, for the same reason people play devil's advocate.
Re: Why should I have written ZeroMQ in C, not C++ (2012)
#36This actually sounds like an argument for why he should've used a smaller subset (or different) of C++. For example: make all constructors private and empty and use public static factory methods for manufacturing new instances. Now the factory can fail, and return an error to boot. Similarly, ditch C++ exceptions and introduce the notion of a status object that methods return. You always have the option of C-style se…
And so I will continue to avoid C++ because I'm not a master and will not avoid the many pitfals, and I want to get things done, not become a master of C++.
Re: Why should I have written ZeroMQ in C, not C++ (2012)
#37Re: Why should I have written ZeroMQ in C, not C++ (2012)
#38Interesting article. So, more confirmation C++ is inferior for writing predictable or high performance applications. I actually see an opportunity for a C-compatible or C-competitive systems language here to beat C++ at its own game. Zero-cost abstractions plus solving C++'s specific problems, painless C FFI, and compilation to C (or LLVM) to leverage their compilers. Might make a nice combo. I doubt we'll see much t…
Re: Why should I have written ZeroMQ in C, not C++ (2012)
#39Re: Why should I have written ZeroMQ in C, not C++ (2012)
#40This actually sounds like an argument for why he should've used a smaller subset (or different) of C++. For example: make all constructors private and empty and use public static factory methods for manufacturing new instances. Now the factory can fail, and return an error to boot. Similarly, ditch C++ exceptions and introduce the notion of a status object that methods return. You always have the option of C-style se…