12 ms·
I will choose one “magic” annotation over repeating the same buggy code thousands of times. Not having abstraction is just as bad as too much.
by kaba0 5y ago
I will choose one “magic” annotation over repeating the same buggy code thousands of times. Not having abstraction is just as bad as too much.
- Thaxll 5y agoAnd yet in Go you don't have NPE that plagues Java code.
- Jach 5y agoThey haven't really been a plague for a while, not like they used to be. A lot of forces are behind it, my top three reasons would be 1) because of the Optional type and Optional mapping makes them easy to avoid in chained calls and is less ugly than a nest of null checks or the equivalent err != nil mess in Go, 2) because of better development practices becoming more common like SOLID and especially https://en.wikipedia.org/wiki/Law_of_Demeter https://en.wikipedia.org/wiki/Law_of_Demeter and 3) because of functional programming styles becoming more widely adopted, with Clojure/Scala/Kotlin showing what's possible on the same JVM.
- throwaway894345 5y ago> less ugly than a nest of null checks or the equivalent err != nil mess in Go "null checks are ugly and error handling is messy" are your opinions, not objective facts. I actually prefer Rust-like enums, but short of that, I think Go's error and nil handling seems quite a lot nicer in practice than Java's `Optional` facilities. Note that these are my opinions, and I'm not posing them as objective facts.
- Jach 5y agoUsing the word "ugly" marks the opinion as inherently subjective.
- throwaway894345 5y agoIn whichever case, a subjective argument is very weak.
- Jach 5y agoOk.
- throwaway894345 5y agoThis is transparently a false dichotomy. No Go programmers are "repeating buggy code thousands of times". Go has a bit more boilerplate than Java until generics land, but I maintain that it's a non-problem 99% of the time (mostly it's just the simplest of conditionals and for loops). And anyway, a generic type system is a much nicer solution than an annotation or other magic.
- kaba0 5y agoHow about eg. transaction management, resource handling, db connection pooling? Could Go implement “generic” solutions for that? The declarative/meta-programming aspects can make common use cases extremely easy to implement (and web frameworks are full of already implemented 100x times functionalities)
- throwaway894345 5y agoYeah, Go has generic db connection pooling in the standard library. I'm not sure what transaction management or resource handling you're referring to specifically, but for resource management we usually just do `defer foo.Close()` or similar, although I prefer to make `func withFile(fileName string, callback func(*os.File) error) error` helpers that open a file, pass it to the callback, and then close it. To your point, we have to write one of these helpers per resource type, but it's such a small, simple amount of boilerplate that I don't even bother putting that into a package to reuse. Not a problem in practice.