Re:Away from Exceptions: Errors as Values
by Joker_vD on Monday August 30, 2021 @07:41AM
(#28354639)
Those v += 1 implement the exact specification given above:
Those are quite strange requirements, and the resulting second code looks strange too, but... it faithfully and obviously correctly represents the given specification.
[ Parent
| on HN ]
Re:Away from Exceptions: Errors as Values
by Jonathanks on Monday August 30, 2021 @04:36PM
(#28360587)
The example is strange and contrived. I couldn't torture the logic enough to demonstrate how readability breaks down with exceptions. Reading through the comments, I realise that even if the code is unreadable with exceptions, it can be rewritten to be readable.
I updated the article to highlight not only readability, but also compositionality. I also tried to draw parallels with Promises (which are also monadic).
I tried to target the article to intermediate programmers that may not already know most of the concerns raised in the comments, and I surely can't cover enough space on error handling without writing a book.
Thank you for the comments. I've learned more from reading the comments.
Re:Away from Exceptions: Errors as Values
by Cthulhu_ on Monday August 30, 2021 @08:35AM
(#28354981)
It's the kinda assignment where you should look at a higher level - what does it do? What is N used for? What are the possible inputs?
I mean if you start with a set of tests instead of pseudocode written down in text you could probably write something smarter.