3 ms·
I hate writing code in golang, because I have to pepper every single function call with `if err != nil`, but then I think about how much C code I've seen that d
by danudey 2y ago
I hate writing code in golang, because I have to pepper every single function call with `if err != nil`, but then I think about how much C code I've seen that doesn't do that and I wonder how much of it should.
- SAI_Peregrinus 2y agoLots! Also lots of C code that doesn't properly check `errno` for things like `strtol` to check for errors that aren't returned directly from a function.
- hot_gril 2y agoGolang's error handling is safer than C's, but it's more cumbersome than it needs to be. In high-level code, nearly every func you write can return an error, and 99% of the time you're just going to pass the error up. Webserver will catch all and send 4xx or 5xx, for example. Exceptions are a lot more convenient and encourage solid error handling. Rust chose a good in-between (the "?" unwrapping syntax). In mid or low level code, anything can still fail, but I suspect the performance impact of supporting exceptions or similar for basic operations (integer overflow, div by 0, etc) wouldn't be worthwhile vs just crashing the program or doing something else. Interestingly, Rust doesn't crash in this case: https://doc.rust-lang.org/book/ch03-02-data-types.html https://doc.rust-lang.org/book/ch03-02-data-types.html
- pjmlp 2y agoEvery now and then I think about forking Go and adding something like ?, and Pascal/Modula-2 like enumerations. However then I realise, why bother, and go back into using C#, Java, D instead.
- hot_gril 2y agoThe only thing I seriously plan to use Golang for is implementing a scripting language in my spare time. Its threading model (greenthreads flexibly mapped to OS threads) is attractive for that.