5 ms·
My personal experience is very different. Of course I have seen bad Go code in the ~5 years I do Go development professionally. But when compared to previous m
by fileeditview 6y ago
My personal experience is very different. Of course I have seen bad Go code in the ~5 years I do Go development professionally.
But when compared to previous monstrosities in C++ or Java with exceptions cluttered everywhere, deep inheritance trees that are absolutely useless..
then Go code is an absolute breeze to read and work with. The one thing I see frequently and dislike a lot in Go code bases is the frequent usage of interfaces for single structs just for the sake of mocking for unit tests.
Often I see cases where you could just strip the whole layer of crap and unit test the real functions themselves. But nobody seems to think about that. It seems that this "write interfaces for everything and then mock/test this" pattern is dominating currently.
- thayne 6y ago> But when compared to previous monstrosities in C++ or Java Perhaps part of it is the languages we are comparing to? I'm comparing to languages such as rust and scala, and to some extent python and ruby. > with exceptions cluttered everywhere I prefer errors to be part of the return value to exceptions, but I also find repeating if err != nil { return nil, err } for almost every line of significant code in go functions pretty distracting. I much prefer rust's `?` operator. Or haskell's do notation (or scala's roughly equivalent for/yield). > deep inheritance trees that are absolutely useless. uh, you can have deep inheritance trees in Go, and not have them in Java or C++, I'm not sure what your point is.
- fileeditview 6y ago> Perhaps part of it is the languages we are comparing to? I'm comparing to languages such as rust and scala, and to some extent python and ruby. I think you should compare to languages that have a similar purpose / area of usage. In my experience that is C++ and mostly Java. I wouldn't dare compare dynamically typed and interpreted languages with Go.. what's the point? I don't have much experience with Rust so I cannot compare it and additionally it's rarely used in companies. Scala I just don't like personally. For my taste it just "is too much of everything". > ... err != nil ... In the beginning I was thinking the same. Over time I got used to it. When I write it I use a snippet. And clearly reading the flow of the error has been beneficial to me a lot of times. Yes it is verbose. > uh, you can have deep inheritance trees in Go, and not have them in Java or C++, I'm not sure what your point is. I am sure you know that there is no inheritance in Go so I am not totally sure what you are getting at. My point is that I think OOP by composition is a lot clearer than by inheritance. Also composition is not overused in Go as say inheritance is overused in Java.
- shakow 6y ago> I am sure you know that there is no inheritance in Go https://golangdocs.com/inheritance-in-golang https://golangdocs.com/inheritance-in-golang
- majewsky 6y agoThis tries really hard to look like an official resource, but it seems to be run by some random IT consultancy. What they call inheritance is a narrow syntactic sugar intended to forward method calls to a member without having to write something like func (x Outer) Frobnicate(val int) { x.inner.Frobnicate(val) } by hand. It's arguably not inheritance because Liskov substitution is not permitted: type Outer struct { Inner } func process(i Inner) { ... } var x Outer process(x) // ERROR: type mismatch process(x.Inner) // OK
- arp242 6y agoThis is a bad article; struct embedding is not inheritance, and mistaking it for such is a classic case of "Java/Python programmer tries to use Go and shoehorns concepts from those languages in Go" that the post mentions. This entire website seems pretty ... meh. It's like the W3Schools of Go.
- thayne 6y ago> I think you should compare to languages that have a similar purpose / area of usage. In my experience that is C++ and mostly Java. The languages I listed first were rust and scala, which serve very similar purposes to c++ and java. In fact, rust is closer to c++ (no GC, more direct memory control) and scala is closer to java (runs on JVM) than go is to either. > Over time I got used to it. When I write it I use a snippet. Which is my point. You have to get used to things like this, which probably adds about as much cognitive load as having something in the language to reduce this noise (although I think this is an known problem in go and may be improved in a future version). > I am sure you know that there is no inheritance in Go Fine. Replace "inheritance" with struct embedding and/or interface hierarchies, and you can get a similar effect. My point is you can have overly abstracted designs in either language.