3 ms·
If something is exceptional you should throw an exception. This is so stereotypical of the object-oriented mindset and Java programmers are the worst offenders
by Annatar 9y ago
If something is exceptional you should throw an exception.
This is so stereotypical of the object-oriented mindset and Java programmers are the worst offenders. If I had a programmer under me who came up with this, I would fire them on the spot and enjoy every nanosecond while doing it.
The “punt and throw an exception” mentality goes directly against the art of UNIX programming rule of repair: repair what you can, but if you must fail, do it as soon and as noisily as possible. What this means in practice is that in 99% of the cases, the programmer could have written the code to either deal with the problem or had enough information from disparate sources to reconstruct the missing data but they chose to punt and throw an exception instead. To me as a programmer, that is infuriating!
Which leads me to point 2.: the exception paradigm requires the intimate knowledge of the software to interpret, as it normally vomits a call stack trace. But in production, to the user of the application or the poor system administrator, or even to the programmer who isn’t intimately familiar with the software, that information is nothing but retching vomit, often with no clues as to what went wrong where! And did you notice how the punter is never around to decipher the gobledygook when this happens? Also infuriating.
Stop throwing exceptions, get off of your lazy asses and when you can reconstruct the missing information, or detect and correct damaged information, or diagnose the problem, do so and give back meaningful diagnostic telemetry on stderr, but don’t just punt and screw the user or the sysadmin over.
If you’re programming to put the bread on the table, it’s not someone else job to make it work; it’s yours. That’s why you get paid, to make the computer compute. No excuses.
- TeMPOraL 9y ago> but if you must fail, do it as soon and as noisily as possible. So basically, spam on stderr and abort(). This is not exactly better than exceptions. > the exception paradigm requires the intimate knowledge of the software to interpret, as it normally vomits a call stack trace. But in production, to the user of the application or the poor system administrator, or even to the programmer who isn’t intimately familiar with the software, that information is nothing but retching vomit, often with no clues as to what went wrong where! Again, it's printing stuff to stderr, or having the exception system print stuff plus stack trace to stderr. The latter is strictly better than the former. It gives you more clue than printing what would otherwise be an exception message to stderr and aborting on the spot. And using exceptions do not preclude you from being able to "repair what you can". In fact, it can help it. I don't like exception abuse either, but it's still better than the C way.
- astura 9y agoYou are ranting against something the author absolutely did not say.