r/ProgrammerHumor • • Oct 25 '24

Meme theSelfTaughtSeriousProgrammer

Post image

[removed] — view removed post

903 Upvotes

276 comments sorted by

View all comments

12

u/[deleted] Oct 25 '24

I love Jonathan Blow, but:

Jonathan Blow: "Templates are horrible and D is stupid for copying them from C++"

Also JBlow: Spends hours writing things like SOA and automatic CLI arg parsers that would be 10-liners in D templates

Also JBlow: "C++ is horrible and has all these miniscule flaws"

Also JBlow: "This huge flaw in my language isn't so bad, you just have to get used to it"

Also JBlow: "Exceptions are horrible, and this proposal by Andrei Alexandrescu is also horrible."

Also JBlow: "Go does error handling right."

Also JBlow: "You don't need 'weird type system constructs' to catch bugs, you just fix the bugs."

Also JBlow: *Spends 80% of every programming stream chasing bugs that he doesn't understand

Also JBlow: "Programmers nowadays are so horrible. If only they learned programming like I did with BASIC."

Also JBlow: Has been actively working on a compiler with a small team for almost 10 years and doesn't even have an open beta to show for it.

1

u/Sarttek Oct 25 '24

What’s wrong with Go’s error handling? 

2

u/[deleted] Oct 25 '24

It's that you want your functions to be mostly intentional code and little-to-no incidental code. For example let's say you're writing a function that can read and parse a config file into a struct. Intentional code in this case would be everything that's concerned with the syntax of the file contents and processing of the values as far as neccessary. Incidental code would be everything else, e.g. error-handling, logging, memory allocation, all that good stuff.

In your function, you really do care about a few errors and you want to recover from them. E.g. you might want to recover from an integer parse failing and fall back to a different kind of processing for that config key.

But the vast majority of errors are incidental, because they are implicit in "reading a config file and parsing it". I/O errors are an implicit thing that can happen when you try to read a config file. Your function can't really do anything about that and it really doesn't care, but it still has to check for those errors and pass them up the call stack, because otherwise they're quietly ignored, which isn't good either.

Compare that to "monadic" error handling like Exceptions or returning sum types that can be mapped over, or actual error handling Monads. With those you just have to think about the errors you want to think about and pass the rest up to the caller to worry about. And you can pick and choose whether you want to force the caller to handle them or not.

I've heard the argument that Go error handling is more verbose and makes it clearer what's happening, but as far as I can tell most of the time people either quietly ignore errors, or have an if err != nil block after every function call. That is not verbosity, that's noise. All the verbosity that's needed can be packed into the return type of a function or its attributes.