6 ms·
One of the motivating examples for exceptions, at the time when they were beginning to appear in mainstream languages like Ada, was to allow people to write ari
by mjw1007 5y ago
One of the motivating examples for exceptions, at the time when they were beginning to appear in mainstream languages like Ada, was to allow people to write arithmetic expressions using familiar notation, while still having a place to put an error handler for the overflow case.
Perhaps the lesson of the last forty years or so is that this convenience wasn't worth adding such a heavyweight feature to the language, but it seems to me that modern languages are still weak at handling overflow.
- pjmlp 5y agoC++ is the only language where exceptions are such an ideology war. All the other ones that have born with exceptions don't have this issue, including Ada.
- masklinn 5y agoI'm not sure that's true. Exceptions are a big issue in Javascript, though mostly because they're absolutely terrible. Whether to use exceptions or not is a common question in e.g. C#, and several APIs are duplicated to have both exception-based and values-based variants. And Python is oft criticised for using exceptions more than once every blue moon.
- ncmncm 5y agoNo legitimate conclusions can be drawn from Java or C# experience, besides that it is best to stay well clear of them.
- pjmlp 5y agoIt is a big difference to offer both kinds of APIs, or to make endless flamewars with compiler runtime forks, which is what disabling exceptions and RTTI mean in practice, a fork from ISO C++.
- Koshkin 5y agoThere are only two kinds of languages: the ones people complain about and the ones nobody uses. ― Bjarne Stroustrup
- pyjarrett 5y agoAda exceptions are fundamentally different from C++ since they only carry type data with a possible message and no other user-defined data. Old school C++ used to have additional try/catch blocks (and performance hit) inserted to ensure that functions match the given exception signature. Also, C++ usually focuses on performance, so all of the bookkeeping required for exceptions could historically be the last 3% or so difference between making your FPS rate or not.
- pjmlp 5y agoFPS rate should not drive what 99% of other C++ developers are able to use the language for.
- pyjarrett 5y agoA lot of C++ developers outside of games don't use exceptions. It introduces a latent and hidden goto up the call chain in your code, and require additional bookkeeping by the program which slows things down. They're also dangerous when you update code because if you introduce a new exception in a function you need to update all of the call-sites. When doing this with monads or sum types, this refactor can be supported by the compiler as a function signature change. It boggles my mind that Ada decided to include them. Unless you go through the entire call chain or use SPARK, you don't know for certain that one of the called subprograms won't throw. Even then, you could still get a `Storage_Error` or `Program_Error` for various reasons.
- pjmlp 5y agoAnd many more of them do use them. Unfortunely C++ suffers from having people that are so crazy about performance, yet never bother to learn how to use a profiler. That is what boggles my mind, how one can be writing C++ as if they were fitting Assembly into 8 bit home computers, but never bother to learn how to use something like V-Tune. By the way, there are other languages besides Ada with exceptions used for systems programming, and if they aren't as big as C++ it is only due to how market adoption has evolved, which had lots of factors not "does the language do exceptions". CLU, Cedar, Modula-2, Modula-3, Object Pascal, D