287 points · by milap · 7y ago · 75 comments
This is wrong. https://golang.org/doc/effective_go.html#channels
> Receivers always block until there is data to receive. If the channel is unbuffered, the sender blocks until the receiver has received the value. If the channel has a buffer, the sender blocks only until the value has been copied to the buffer; if the buffer is full, this means waiting until some receiver has retrieved a value.
We switched from Python to Go over 2 years ago and it's been an amazing improvement in terms of performance as well as developer productivity for building high traffic endpoints.
Feedback welcome.
Also there are ways to talk back and forth with Electron for front end.
Full disclosure, have not tried either but just looking around as I get into Go.
I do a lot of web dev so like idea of HTML/JS for front end. I know I know, Electron is awful but maybe less awful if it's light?
My main concern with the article is the massive abundance of typos. Like more so than a normal article written by a programmer. They make me stop and double check if I read it wrong, it is a term or something I haven't seen before, or just a typo.
The syntax is in the vein of C and Python, so it's probably familiar. The language itself is fairly small, and the focus is on simplicity over expressiveness. If you want to learn new languages but have limited time, my answer is to take a look at Go.
With that in mind, spaced repetition is a great technique that fits with having limited time in small blocks. Squeezing in some time here and there becomes a strength instead of a weakness.
EDIT:
as my time for learning new programming languages is limited, I would invest it in learning Rust, rather than learning Golang or learning both of them.
IMO the only reason to learn Golang is if your already have a legacy Golang codebase or if you want to contribute to various open source projects written in Go, like for example Kubernetes (my first experience with Golang was trying to compile a patched Hashicorp project).
It's the same as suggesting to a front-end dev, skipping Backbone, Ember and Angular and going straight for React.
There are lots of overlapping technologies in our space and learning all of them is a huge time waste.
I agree.
That's why I invested time into looking at Go over Rust.
Go will be the better choice for most programs most developers will write. Go 2 even more so. Rust is too complex, and for the applications where a garbage collector is acceptable (>99% of them) it isn't worth it.
On the other hand, I hear good things about Go across lots of people I work with although I've yet to sit down and give it a meaningful try. But I also have concerns about the maturity of a language who has jumped to V2 in what seems like a relatively small amount of time.
I'm inclined to believe both languages have lots of promise and could easily be the future of software development, but I'd be hesitant to pick either for a project that needs to be maintainable for a long time in case the language changes too much and leaves you with technical debt.
This is really not a topic for language flamewars and it's even against HN guidelines. I don't understand why people need to scream rust in every other language post like if it was a religion.
The lack of even a dynamic array (c++ vector, Java arraylist) means you write a lot of 2-3 lines of slice notation phrases that require stopping and thinking about indices you wouldn't need to in other languages (and creating a lot of zero length slices for boundary conditions that shouldn't be needed). Also no balanced tree is a big issue (googles side implemention sucks in that the comparator cannot be passed in).
I recently tried to write some small library functions using sqlx to do arbitrary sql queries and then some munging of the results before returning it. It was extremely difficult.
The language feels half done at times. I find it hard to believe that Google used it much internally before releasing it. So many unfinished corners.
Generics would go a long way to fixing some of these issues.
While the ahead of time compilation is nice and had lead to me using it for things that need fast startup (some shell like scripts and literally old school cgi), it often seems like a worse Java.
If you don't like Java's verbosity, go's from my small use is about twice as bad. 300 lines of go does surprisingly little - part of this is gofmt's fault though.
Also, does anybody know of good performance tests between Java and go? I mean like well written and optimised. Most tests over I've are very poorly written and do dumb things like include hotspot startup and compilation times. Hotspot can generate some very slick code, but it just takes 10k passes to get up that point.
More generally. I like the idea of community driven benchmarks where each community tries to make representative, performant samples to realistic problems. All too often you get an expert in one language making a benchmark against a language they are not experienced with and getting really improper results.
I had a feeling go was slow, but I didn't expect such poor performance numbers. Some of that is probably the heavy reliance in reflection. For example they json parsing you need to go to the bottom of the list to find a go program, and go's json library makes extensive use of reflection and tags to guide the parsing.
It is somewhat ironic that go's big feature was AOT compilation static type checking, but it seems to immediately devolving into reflection and parsing tag key value strings to do anything. I had a typo on one of those they other day and could find the bug for an hour.
In real code that I write, most projects never import reflect. Sometimes I import it in tests.
golang ranks 108 and 121 in the plaintext and JSON benchmarks, which is quite abysmal.
[1] https://www.techempower.com/benchmarks/#section=test&runid=b...
[1] https://www.techempower.com/benchmarks/#section=test&runid=b...
Are go slices not dynamic arrays? They grow automatically when necessary.
And you can have memory leak issues if you forget to zero a reference since the backing array still holds the reference. And none of that is efficient. A lot of temps and unnecessary copying going on.
This is by design, to lift the CPU and allocation costs to the foreground. You can argue that was a bad design decision, but it wasn't an oversight, as you imply in the OP.
Removing an item from a list (that is actually performant enough that you'd want to use it) in Java is also a copy though, unless you're removing the last element. Underneath the hood, there's a copy. Same deal with insert.
Given the number of times I've seen insert or remove used where it really, really shouldn't, I'm not so sure the lack of insert/remove is a bad thing.
But yea I do get that general feeling that golang sort of... distrusts the programmer. Like the opposite of C++, where it assumes you're God, but then happily vaporizes you with God-powered-lasers.
I don't work there, but I don't think it's used internally in any significant manner at all. Most development there is done in C++, Java, and Python.