Why I Don't Like Golang (2016)
teamten.com
teamten.com
Ruby - for problems that are programmer bound - regular web servers / APIs, CRUD.
Go - for problems that are CPU / Memory bound - fast servers, proxies, APIs with lots of long I/O waits or high RPS requirements.
Java - for problems that require modelling - logistics systems, data structures, algorithm heavy or design heavy problems
JS/React - for UI
1. I built a Go implementation of resque. This let us swap any async process. Things that needed async tended to benefit from Go's speedup.
2. We also moved some internal APIs to Go in a sidecar server to help build up/validate core library implantations before replacing whole endpoints.
You want a simple, expressive language, like python with django, or ruby with rails or sinatra. You want to implement most of your application in this language, because these languages allow programmers to be very, very productive. Put in a dumb way - 10 to 20 lines of ruby with modern libraries go a really long way without golfing.
And if you notice you need performance and low latency, switch to your second language, java or go or something like that. This should be very little code, so you can throw all the really ugly optimizations at it to make it go fast. I've pushed some java services to sub-millisecond response times, but the things you gotta do with netty and lock-free data structures aren't suitable for a general audience anymore.
And I guess, on top of that you need some kinda request routing, but that's simple to do with nginx/haproxy or some kind of DNS / service discovery provided by an orchestration system.
When I was a cowboy solo coder I'd never use anything but things like python, but having worked in teams, they have limitations.
These days you get decent enough libraries even in lisp languages.
That was my take away. In fact many of the points made in the negative are actually positives for me :
- capitalization - I actually think it's much easier to spot the public API with this convention
- no exceptions - I get the concern about forgetting to handle and I think a compiler error for unhandled unhandled return values would be great. I also think golint probably handles this.
Other issues can be solved easily with tooling (goimports). I admit, I love the language and I feel very productive working in it. Error handling has NEVER been more successful - that's my number one praise.
I'll take writing tags, thanks.
I guess it's a difference of perspective: do you let the outside world's naming conventions leak into your codebase, or do you translate at the boundary? Go's field tags chooses to keep consistent naming internally and translate at the boundary, in exchange for defining that translation explicitly. Note, in some cases you will have conflicts no matter what you choose (e.g. serializing both json and database).
The outside world is going to be messy and inconsistent and full of conflicts. I would prefer to keep that external to my codebase as much as possible and follow a consistent naming convention within the language instead of letting the outside world and its whims dictate it.
You can use `#[serde(rename_all = "camelCase")]`[1] in the struct to apply the fix to all fields.
I used to hate it 8 years ago, but the project I’m working on has a modeling heavy problem, and Java with the immutable data structures in Guava was a good match. Was just blown away by the language now. Still clunky, but there’s something to be said for a compiled language with great tooling, effortless refactoring and budding expressiveness.
That said, I personally don't think Kotlin went nearly far enough, and some of their design decisions are questionable but if need to be in the Java ecosystem it's a nice choice.
I'm also, let's face it, pretty jaded at this point. Lack of extension methods makes for code that's less clean-looking than I'd like it to be, but otherwise it's NBD. There are plenty of other language features that I straight up bang my head on that I'd like to see change first. Most of them are ones that affect Kotlin every bit as much as they affect Java.
But, I must say, I do really like that Go makes the AST a first-class citizen and a core part of the standard library. While not strictly a Go thing, in the languages I usually find myself programming in you have to rely on third-party implementations of varying degrees of quality or, even more common from what I see in the wild, messy string building. Being able to focus on generating the tree and have the built-in printer generate the code in the format that Go users expect is a much nicer way to generate code.
Seconded. But I wish they would go one step further and make its compilation / code generation a first-class citizen too, including dynamic loading of generated code.
The .NET framework has had it for a while, but it got removed in .NET Core.
EDIT: Why the downvoting? Sure, there are valid issues with golang, but there are also a small but vocal minority on HN who enjoy being rude to Google because they don't like Google, which is what my comment relates to. I certainly don't have any axe to grind with the author, the article, or the commenter to whom I'm responding. It was just a perspective on why, in general, golang might get more of a slating than it perhaps deserves, and I acknowledge that amongst that there will obviously be some people who have many valid reasons not to like golang. Sheesh.
I work and live in SF. Of people I talk to in real life who’ve used golang for non-Google, non-toy projects, sentiment is at least 4-to-1 against it, and in my anecdata that ratio generally increases as people use it for longer.
The one consistent praise I’ve heard that seems genuine (and that I don’t entirely disagree with) is that it’s easy for a new team member to jump on board and be productive. Which sounds great, but if this is what you’re optimizing for at (in my opinion) the expense of nearly everything else, then it seems like a self-fulfilling prophecy of high turnover.
1) Value types - in Java if you want an array of objects of a non-primitive type, each one will be individually heap allocated (with some extra per-object overhead) and stored as an array of pointers (may change in Java 10). Go allows objects to be linear in memory with no overhead.
2) Slices everywhere - in Go slices are the default list representation. This allows any API that takes a list of objects to be passed a range of a bigger list, without copying/allocating.
3) Low-latency garbage collector - I believe Go has one of the lowest latency garbage collectors in common use (sub-1ms pauses). I realize Java has several options, but I think Go's is lower latency than all but some commercial/exotic ones like Zing. This is not saying the GC is better all around, just on latency. It's also relatively easy to minimize allocations in Go due to value types.
4) Low-overhead concurrency - lightweight tasks with no blocking/non-blocking dichotomy in APIs. But threads can scale up a lot, so this might not be a big benefit depending on the application.
5) Interior pointers - you can lay out structures linearly, and still use interior pointers. Also, you can use them as interfaces without allocating any 'boxed' objects.
There's probably more, but these are the things that come to mind right now. Looking back on this list, all of them are performance related. So if an application isn't performance sensitive in any of these ways I guess it would be understandable that someone might not see much in it, compared to a language with a higher learning curve but a lot of conveniences like Kotlin. Things like capitalization don't seem that big an issue though... maybe because Go is a simple language the tooling is already pretty good, and you can easily rename to upper/lower case in an IDE like GoLand.
For people unfamiliar with Go and want to see something more than hello world, I think an interesting project to look at is https://github.com/fogleman/pt. It's not enormous but not trivial either and makes use of interfaces, goroutines etc. The author's other projects are great too.
The author of the article doesn't mention Google, but that's not what my comment was about: it was a (very mild) observation that there are some people, and I'm sure by no means the majority nor anywhere close, who will neg on Google and their tech, because they don't like Google.
So after reading about golang over and over, it seems it is going the MongoDB way. A lot of excitement at the start because it's easy and fast to put something out but as soon as maintenance mode needs to kick in, people realize it is not the silver bullet and maybe not even a ok solution.
But isn't that a problem of the whole industry? First a hype gets build up and a lot of people jump on the band wagon. Then the real world kicks in and some complain overly loud and others chime in with "I told you so". Finally a lot of people change the tech stack silently because nobody likes to talk about their failures too much.
I can't say if it is the same with golang, I did not use it at all yet, but some design decisions are at least doubtful.
Go and its history shares a lot of similarities with Java, but it hasn't had its 5.0 moment yet
1) The discussion gives insight to people who have never used Go. The usual way of getting that kind of knowledge is to shoot yourself in the foot and learn from it.
2) The back-and-forth can provide useful advice on how to work around certain problems in Go.
3) Language designers can always use these discussions to guide and inform their decisions. "Hmmmm, haven't thought of that, better make sure my language doesn't do this; that other thing is an acceptable tradeoff, though."
Additionally, I think it's important to point out the flaws or, maybe better-put "trade-offs" of technologies, especially when they are very popular. I think it's important to temper the hype and share collective engineering wisdom.
I think more constructive articles and titles would be like "What I Wish I Could Change About Golang" and would include background on how long the author has been writing Go and in what context.
Just like this guy you (or your colleges) might actually have been fooled by curiosity and hype to write some code and put it in production, and when you realize how bad it actually is (this was only a personal top 10). At least you should try to fight back against the hype and try to warn people.
Still think the general sentiment is quite go positive overall, go definitely needs more critique.
Even if I don’t us a language, I very much enjoy these sorts of “after x years review” since I definitely won’t be getting x years in each. They force me think in terms of doing things with a computer easily/language design, which is the point of all of this. This perspective help me see the shortcomings in whatever language I’m using and helps me remember to not get stuck in it.
It's normal. After the initial hype 3/4 years ago, developers are taking a harder look at that language and with experience its flaws have become more obvious.
Go type system definitely has problems that aren't addressed by its designers, IMHO limiting its adoption.
> A lot of people seem to have to voice their dislike for it instead of just not using the language.
One can use a language daily while still remaining critical of it. People who don't use Go don't care about Go. Only people using Go will complain about its shortcomings.
A lot of Go issues have actually been addressed in previous languages such as Ada. Ada tasks for instance are close to go-routines and they use the same "select" system to deal with concurrent messages. However, Ada tasks unlike go-routines are "objects" that can be referenced as variable, they also can scheduled by the developer.
There is not a single language out there free of criticism, Go isn't different. So it shouldn't really be striking at all.
Wouldn't that break the promise of backwards compatibility that they made with major versions? They could probably do that in Go 2.
Personally, I think D is a more mature language, design wise, although it's a bit lacking in terms of libraries compared to Go and the tooling is, also lacking compared to Rust.
I think pouring cold water on excessive hype is, on balance, probably a good thing.
The one defense I’ve heard is that it allows you to define interfaces that are implemented by types you don’t control, but this completely ignores the fact that doing so implicitly isn’t necessary for such a feature, and other languages (e.g., Rust) elegantly demonstrate why that is.
There's an Uncle Bob talk I watched a while back where he suggests that oftentimes language designers will say just about anything to avoid admitting that the real reason a feature is absent or was implemented in a hacky way is for the convenience of the compiler's authors.
Help me understand this. The concern raised by the author regarding method signatures versus method contracts seems valid, and I have a hard time envisioning where implicit interfaces would be useful. Do you just hope to get lucky? Somebody, without knowing about the interface, would have to use all the same parameters and return types, the same method name, and implement the contract in a compatible way for it to work, right?
1. No default function parameter values.
2. You can't require struct fields. So, you can make a new struct, and then later try to access a field, you get a runtime error (that the compiler didn't catch).
The second can effectively be solved similarly to the first. If a struct could take a default value (like a class), then you wouldn't miss something like creating an empty slice.
2 is so annoying. Half the sdtlib wants you to use `foo.NewStruct()` and the other half uses `&bar.Struct{}`. As far as I can tell the rule is to use a bare definition where possible and only declare a New function if the zero value isn't meaningful. But there's no way for a library author to force the use of new and/or disable bare struct literals, and there's no way for an API consumer to know which category a given library will fall into other than by rote memorization. It's practically designed to invite user error.
Both of these seem emblematic of a bigger problem in the design philosophy of go. It's optimized for simplicity, but often at the expense of making idiot proof interfaces difficult or impossible to build. This seems like a fundamental misunderstanding of what makes programming difficult in the first place. My package's users (including future me) aren't going to know or care about how the internals of whatever I'm throwing together work, they just want to use the API to solve their problem with as little extra contextual knowledge as possible. Go doesn't let me write an interface where they don't have to know or care, all in service of a definition of "simplicity" that doesn't seem to actually make anything easier.
That's function overloading rather than variadic functions. Variadic would be `add(xs int..)` where you can pass in any number of int, and they'll be collected into a slice or whatever.
But technically speaking it is optimized for simplicity of reading code. The idea, whether it has worked out in practice or not, was that Google could take people with limited developer experience and put them into a Go codebase and have them be able to follow along with the project with minimal introduction and explanation from already busy teammates.
Your function overloading (Go does support veridic functions!) example is a good example of where the author and compiler know full-well what the intent is, but people coming in five years later may not be entire clear on what you are trying to say. `add` is a simplistic example, but it is easy to see, and I am sure many of us have experienced, how this can be a problem in more complicated cases.
As you have pointed out, optimizing for the simplicity of reading has resulted in increased complexity of implementation. You've only just scratch the surface of the gotchas in Go. However, that's the tradeoff. Engineering is all about managing tradeoffs and some will value readability (assuming the theory that Google has holds – I don't know that anyone has formally measured this) and others will value writability. Everyone has different goals and is developing in different environments. There is never going to be a solution that fits everyone. If there were, we wouldn't need software engineers anymore.
In other words, go makes it extremely clear how a piece of code works at the expense of knowing what a piece of code is trying to accomplish and why I might want to invoke it. I generally think that's a poor tradeoff.
That said, perhaps they have and don't want to admit that Go falls short. But they've been open about being wrong before when applying the scientific method and getting unexpected results.
it isn't even easy to read bog standard code made out of for loops glued together (because that's all you have to work with)
every time i look at another tedious manually written set operation that would been have a simple expression in another language (python is an excellent example) i am deeply pained. every time failure of abstraction forces you to re-implement such things there are opportunities for bugs to creep in.
go is designed to be easy to write, and (in my experience so far) the natural consequence is that any project made up of modules spanning more than one or two directories quickly becomes very, very hard to read.
a common exception to that is when code has to do many set-like operations, which can become very hard to read without having to sprawl out beyond even a single file. very common when dealing with multi-parameter/multi-result RPCs
The flat namespacing is rough at times, but you get used to it. It also encourages you to be judicious in what you make global, which is imo a great thing. I haven't had a problem with capitalization. It's jarring at first, but you just get used to it.
There also isn't nearly as much magic as that cherry-picked example might lead you to believe. Then again, having worked with Ruby/RoR, I've seen just how gross magical behavior can get shudders and maybe my definition of 'magical' is a bit more forgiving. I'd like to see a more comprehensive list of such grievances.
It's possible that the Go ecosystem has improved considerably since the author wrote this (~1.66 years ago), so I'd love to hear his take on it in the present day. I do agree entirely about the horrific use of interfaces and lack of generics. I'll also throw in the lack of enums and poor default error convention/semantics as additional glaring issues.
This is all made that much more vexing by the fact that Go is so damn close to being a really great language.
The language they were shooting for feels like "C with garbage collection". The language they were actually aiming for was probably closer to "something we can easily transpile python to".
In the end, the language they got is a bit of a mess, with fairly arbitrary hyper-pedantry causing more problems than it solves.
I still use it, but so far only in the small.
Why anyone who doesn't share Google's unique issues would want to use it, though, is beyond me.
As I see it, programming is something of a craft, people have different opinions about how to do it, and the only real way to evaluate these opinions is to have a lot of experience.
Not having a great deal of experience, I like that Go essentially proscribes a lot of the stuff people normally have opinions about. It pushes you to write in a way that, for better or worse, some people think is good. I trust their understanding of the tradeoffs involved in engineering software better than mine - and I also trust that, when I outgrow them, I'll notice.
This complaint sounds like it's more about Go doing it differently than the language the writer is used to.
> 2. Structs do not explicitly declare which interfaces they implement.
It sounds like this is probably to have structs that will please several interfaces, but I can't find a good example of that in the go std lib. Anyone?
> 3. It’s far too easy to forget to check errors
use a linter that warns you when you do this
> 4. if I name my source file i_love_linux.go
That's actually a pretty cool and light way to implement something for multiple platforms I thought...
> If I accidentally name a function init()
Go has so few forbidden keywords that I can't really appreciate this complaint.
> In Java [...]. Sometimes I find it hard to read Go
So Java is easier to read than Go? Come on!
> I see no good argument for omitting this [ternary] operator
Less ways to write the same thing. Improve code readability.
> Import versioning and vendoring is terrible
I would say Go has the best standard tools. It's not perfect yes, but it's better than other languages.
> No generics
that's a good thing
This post really feels weird when in another thread of HN's FP you have people arguing that a 35 LOC package is a good thing in js.
I didn't realise there are people who prefer this thing.
Generally speaking, what should we think about languages that are theoretically weak but are quite successful? Does that imply that the theories are wrong?
Between
var v T
if (cond0) {
v = value0
} else if (cond1) {
v = value1
} else if (cond2) {
v = value2
} else {
v = default
}
and val v T = cond0 ? value0
: cond1 ? value1
: cond2 ? value2
: default
I'd much rather have the latter. var v T
switch {
case cond0:
v = value0
case cond1:
v = value1
case cond2:
v = value2
default:
v = default
}> However, your if statement is unidiomatic and quite unlike how you would normally write that particular logic in Go. If you really want to make a fair comparison, you might consider writing it in the way that Go is normally written, not the way that someone familiar with another C-style language might write the code if the ternary operator was taken from them.
meant
> the parens are unnecessary
and they didn't just write that because reasons, which would also be the why they commented an other half dozen times since then but just couldn't come around to showing "how you would normally write that particular logic in Go" because it would take all of 5 minutes.
Except for esoteric languages, of course. I've yet to see someone claiming some code in Malbodge is crappy and offering a refactored version. ;) Just kidding.
H = (C == 0 ? null : V == r ? (g - b) / C : V == g ? (b - r) / C + 2 : (r - b) / C + 4);This is even worse in languages that have truthy values, since you don't even have the "== True" thing to help.
let example
if (someCondition) {
example = 3
} else {
example = 4
}
In javascript, for example, like above, I'm initializing a variable (with let, allowing reassign-ability). Its value can be modified later by other code.Alternatively, I could use a ternary operator and a const to avoid potential unwanted reassignments.
const example = (someCondition) ? 3 : 4
------------Some languages, like Kotlin, actually let you use an if-else expression in a single line...
val max = if (a > b) a else b
... or even allow you to return the last line of a block to assign a value: val max = if (a > b) {
print("Choose a")
a
} else {
print("Choose b")
b
}
*val, in Kotlin, is similar to const in javascript; it's not reassignable.The weirdest part is that the author seems to prefer Java. Which is one of the more verbose languages out there.
It's a small nitpick in the grand scheme of things, but it forces me to allow a class of user error (and, in some cases, concurrency issues) that other styles of programming make impossible.
And also it usually adds to the line count, which is annoying.
Care to elaborate? Consider the following:
var foo = func() struct{ Bar int } {
if os.Getenv("BAR") == "1" {
return struct{ Bar int }{1}
}
return struct{ Bar int }{2}
}()
Is there a case where the foo variable can be assigned to something other than one of the two conditional-dependent values?With a given implementation or is there something in the Go specification that prevents this from being compiled away? If I were to write something similar in, say, C++ with a good compiler I would expect the generated code to be equivalent to using a ternary operator.
my_variable = (my_very_long_condition)
? value_if_my_condition_is_true
: value_if_my_condition_is_false;
This is 3 lines, but there is almost no noise, just the condition and alternate values. Also, the variable is never assigned a dummy value (or left unassigned).projectname:
|- go
|-- src
|--- domain.com
|---- username
|----- projectname
|------ Actual Code goes here...
|-- pkg
|-- bin
It's a fun time explaining this to anyone new on the team...Everyone has a different way they like to setup their environment and I didn't want to push my ideas onto other users.
The way you reference is a valid way, but is unorthodox and requires altering GOPATH for each project. If one is worried about polluting a global space of packages as they pull in dependencies (the standard objection), that is what vendoring is for. If someone is not liking all the fuss with altering GOPATHs, that particular grumbling is easy to fix: don't alter it :)
When I first started with Go, I did the whole "alter the GOPATH for each project," until I finally gave in. After, things just got simpler. To each their own.
So I'm inclined to side with the engineers actually putting the hours in instead of the talking mouth bloggers. If there comes a day when Google, or Uber, or Twitch, or Cloudflare comes out and says "Go was a mistake and we're starting to replace our old Go code with this new thing", then I'll start listening.
https://docs.google.com/presentation/d/1LO_WI3N-3p2Wp9PDWyv5...
There's a huge difference between "Go doesn't work for us, here's why, here's what works" and "I don't like Go". The latter should be a Facebook post and has no place on HN.
[1] http://blog.asciinema.org/post/and-now-for-something-complet...
TL;DR: topics covered:
1. capitalization rules create inconsistent behavior
2. Structs do not explicitly declare which interfaces they implement.
3. No exceptions
4. A very good one: "Here’s far too much magical behavior. For example, if I name my source file i_love_linux.go, it won’t get compiled on my Mac. If I accidentally name a function init() it’ll get run automatically. (...) It’s fine for small projects but bites you on large ones, and Go was meant to address the problem of “programming in the large”."
5. Identifier name clashes
6. It’s difficult to generate Go code automatically due to the compiler being picky on imports, etc.
7. No ternary operator.
8. (complaint about sort.interface{} that could have been solved using generics)
9. "Import versioning and vendoring is terrible. "
10. No generics.
11. "The append() function modifies the array in-place when it can, and only returns a different array if it has no place left. You couldn’t ask for worse API design. How many bugs are caused by forgetting to assign the result? A lot, because initial testing may not trigger a resize."
I would personally replace (6) with "absolutely no half-decent metaprogramming abilities (nor an expressive type system that could give you a workaround here.)"
> 4. A very good one: "Here’s far too much magical behavior. For example, if I name my source file i_love_linux.go, it won’t get compiled on my Mac. If I accidentally name a function init() it’ll get run automatically. (...) It’s fine for small projects but bites you on large ones, and Go was meant to address the problem of “programming in the large”."
4. is great for large projects. Once you learn the convention, it is super easy to see which files are for which platforms. It makes it to navigate large trees.
6. Look at how protobufs do it. Easy to work around.
11. Understand how Go works, run go vet.
I'm not saying that it can't be learned/taught. Also, IDEs like GoLand help, but at the end of the day the capitalization approach seems like an unnecessary annoyance
Also, I'm not sure you'll be able to convince me that reading "public" and "private" add meaningful cognitive load to reading code.
It makes it literally impossible to swap one library for another (a rename or fork). A simple example that had caused tons of grief and had probably wasted lots of man-hours is when github.com/Sirupsen/logrus became github.com/sirupsen/logrus.
Vendoring sort of works for simpler "I need a patched version of this" cases, but is not a real solution.
What could be the reason for this?
3. Tooling will catch when you are not appropriately handling errors, although I'm a little bit surprised this didn't already exist in 2016. But I'll assume it didn't. It certainly does now.
6. Again, not a change, but the patterns to make this a non-issue are perhaps better understood now. The points are short on intimate details, so it is difficult to determine if the problem is a result of the author not being entirely familiar with the language the way that people are today, or if there is a particular edge case that the rest of us might not consider.
8. The sort package has addressed this concern.
9. Go has had a solution for versioning from the very start, so I'm not quite sure what the parent is referring to. It was indeed a terrible solution for many organizations, but a lot of work has been done to improve on that. For all intents and purposes this is no longer an issue.
How? Looking at the documentation, you still have to write at least three functions for each type you want to sort.
sort.Slice(people, func(i, j int) bool { return people[i].Name < people[j].Name })I think they are pretty similar to exceptions.
1. Capitalization rules vary by language, I remember struggling with camel cased naming in Java in some scenarios. I also thing the example given is bad, User.user is a poor name in any language.
2. Structs w/ implicit interfaces. I like this feature of Go, and it's never bitten me in the way the author describes. I never liked having to declare them in Java. And there is an easy way to ensure your particular type implements an interface in Go.
3. I prefer not having exceptions, and linters will tell you when you are not checking returned errs. I do wish Go would offer tools to reduce the amount of if err != nil {} blocks, particularly in IO heavy code.
4. Go's build system is very easy to understand compared to something like Makefiles or Maven. I don't consider a few conventions "magic." I have mixed feelings about init(), but I think it's much better than trying to come up with thread-safe alternatives to compile regexp, etc.
5. Naming. Writing unit tests from an outside perspective (package xyz_test) will help you pick better names, and you will run into less conflicts. In Java you see hideous combinations of Abstract, Singleton, Factory, etc. I much prefer Go's concise/pragmatic naming style.
6. I don't do much code generation, can't comment.
7. I do miss ternary sometimes, but I have seen it abused with very long statements in other languages. I would note that "else" has become a code smell in Go, it's more normal to assign a value and then change it.
8. Sorting. I like that not everything needs to be an object in Go. Having to add a few extra lines of code the rare occasion I need to make something sortable is much better than a project full of Java class/getter/setter boiler plate for what should have been a struct.
9. Yes, dependency management is a mess. No argument. Looking forward to dep becoming official.
10. I do sometimes miss generics, but I started writing Java before it had generics so I can live without them :P. I think they can lead to readability problems when overused.
11. append is a bit confusing, but hiding how it works should be considered "magic." linters will help you here.