4 ms·
> Then we had exceptions, which solved the problem of people forgetting to check by crashing the app. They can also harm readability, as just about every state
by MaxBarraclough 6y ago
> Then we had exceptions, which solved the problem of people forgetting to check by crashing the app.
They can also harm readability, as just about every statement can now cause an early return from a block. They also greatly complicate static analysis.
No discussion of the shortcomings of conventional exceptions would be complete without these two excellent blog posts by the great Raymond Chen:
Cleaner, more elegant, and harder to recognize https://devblogs.microsoft.com/oldnewthing/20050114-00/?p=36693 https://devblogs.microsoft.com/oldnewthing/20050114-00/?p=36...
Cleaner, more elegant, and wrong https://devblogs.microsoft.com/oldnewthing/20040422-00/?p=39683 https://devblogs.microsoft.com/oldnewthing/20040422-00/?p=39...
> Attempting to get the complete set of error types that any given call may raise is a fool's errand because of the halting problem it eventually invokes. Forcing people to provide such a list results in the Java problem for the same reason.
The Java problem is one of ergonomics -- unwieldy lists of exception types -- not a computability problem. What do you mean here?
- pjmlp 6y agoThe only programming language where exceptions are such a problem is C++. First of all, because a religious subculture will run to pitchforks and torches at the slight mention of the word exceptions in the room. Then the overall machinery in place to make them work alongside code that was most likely written as C originally. And naturally every ms and byte lost to exceptions infrastructure is a capital felony, so even more fine grained semantics to make it happen. C++ is still the language I reach for when not doing any JVM/.NET language, but things like this is what takes the fun out of using it with another ones on a team.
- MaxBarraclough 6y ago> The only programming language where exceptions are such a problem is C++. I'm not sure what you mean here, neither article is about the low-level issues that arise in C++. The second article only discusses C#. Chen's point is more about the way every call can surprise you by causing your code to return early.
- pjmlp 6y agoEINTR and longjmp can also surprise you, even in middle of calls, yet C doesn't have any exceptions.
- MaxBarraclough 6y agoYou're right that the C language has many weird and wonderful capabilities and footguns. How does that address Chen's point about exceptions being unmanageable?
- pjmlp 6y agoHis point doesn't stand in any programming language that doesn't enforce error checking, exceptions or not, you will be surprised at any possible execution point if you don't check error values from previous call. At least with exceptions you get a "I told you so" if something does happen, and a defined way to force application termination if the error isn't properly handled. Given the remarks on the C++ post, I assume he belongs to the /EH- side of pitch forks and torches, which actually goes against the C++ best practices at Microsoft, https://docs.microsoft.com/en-us/cpp/cpp/errors-and-exception-handling-modern-cpp?view=msvc-160 https://docs.microsoft.com/en-us/cpp/cpp/errors-and-exceptio..., which leaves a feeling of a kind of biased article in some way.