161 points · by geetarista · 13y ago · 181 comments
However, the direction the language took ended up being quite predictable and somewhat of a bore. The problem with Go is that it doesn't seem to fit any particular niche. Some other design decisions were questionable (no exception handling, for one).
I kind of like Go, but I haven't used it for years. There's no real reason to NOT write something in C (or, rarely, C++) or Java, or if I need some serious scaling, Erlang (or just use either something like libevent for C or Kilim for Java).
Go is very D-like. D, like Go, can't really find its niche. If Go or D were more idiomatic, perhaps they would be adopted in early programming classes (high schools and colleges -- like Python, for example), but even though goroutines, channels, and fast compilation are interesting concepts, they aren't really enough to detract from writing in the many other languages that do just about the same thing (and are a lot more popular).
The language, libraries, and ecosystem are miles ahead of where they were back in 2009.
Why not use C? Because C has no sensible packaging system, is unsafe, requires manual memory management, and offers a degree of control that is unnecessary for most tasks. Why not use Java? Because it is verbose and picky and basically forces you to use an IDE to get anything done, etc etc. If there were nothing wrong with these languages (they're the main ones we use at Google) we wouldn't have developed Go.
Use Go more! You'll see why people love it, and why we created it.
I evaluated Go last week (2013-03), but there is no meaningful Eclipse IDE support. goclipse doesn't work half as well as CDT, and not a patch on JDT.
I won't move away from eclipse workflows and project management, the context switch is more expensive than any language benefit.
I'll keep checking for comprehensive Go support in Eclipse, but until then it is a showstopper.
You're letting your tool own you rather than you owning your tool.
Erlang has a great concurrency model, but it's fairly clumsy for writing procedural code of any complexity, which makes it harder to pick up too.
The libraries maybe (and the runtime). The language, as per semantics and syntax, is more or less the same.
>Why not use C? Because C has no sensible packaging system, is unsafe, requires manual memory management, and offers a degree of control that is unnecessary for most tasks.
But is absolutely essential for most tasks C is used. For all the others, why not use a higher level language like Python?
>Why not use Java? Because it is verbose and picky and basically forces you to use an IDE to get anything done, etc etc.
Some people are not "forced": they choose to use an IDE, and wouldn't have it any other way. It is like telling some Smalltalk guy: "Smalltalk forces you to use the smalltalk image editor/environment" -- so what? He is perfectly fine with it. Heck, lots of people even like using dynamic languages with an IDE (and more would, if there was better type inference and assistance).
>If there were nothing wrong with these languages (they're the main ones we use at Google) we wouldn't have developed Go.
Well, the main reasons for Go, as stated in the official pages (the Golang FAQ), are not very convincing or exciting: No header files, faster compilation, parallelism, garbage collection, lighter type usage.
What C programs are you thinking of? Thinking of significant C programs that I have used (bash, apache, gcc, and many more), I can only think of a few that wouldn't be easier to write and maintain were they written in Go, without suffering a meaningful performance penalty. Funnily enough, a lot of the uptake of Go has been from former users of Python, Ruby, and other dynamic languages; they attracted to Go's simplicity, safety, and speed.
But really there's a lot more to Go the faulty dichotomy of "dynamic vs static" (or Python vs C, whatever). This is worh reading: http://talks.golang.org/2012/splash.article
>lots of people even like using dynamic languages with an IDE
Agreed, and I have nothing against IDEs. I have just found that I can't comfortably write Java code by hand. There's way too much boilerplate. In my experience an IDE is essential writing Java code efficiently, and I don't think that's a good thing.
>not very convincing or exciting
Depends on your definition of exciting. Since I've been writing Go code I've been more excited about programming than ever before.
For a project a couple of years ago, I needed to use OpenCV and the Go bindings were quite immature. I just switched to C++ (for that project) and never really returned.
But now that I think about it, whenever people that are interested in being introduced to coding (it happens a lot on campus) ask me "what language should I learn?" I've never answered Go. I'm not sure if most people would.
Certainly not C or C++, if you're discounting Go. I'd also discount Java and C#, since they're syntactically quite similar to Go. Certainly not erlang.
So... python? ruby? While I like those languages, I feel that the lack of a compiler is a pretty big hindrance to new programmers. Statically typed languages can catch many errors that produce some truly strange error messages in dynamic languages.
However, Go seems to be very good at what Python/Ruby/Node.js/Perl are good at. It provides a simple, clean language with more guarantees and better runtime (mainly the cheap goroutines). I see Go taking some of their role for web development, simple tools (Go programs produce a single binary - very easy to distribute).
Apart from Google (who uses it for Youtube), Go hasn't really been used in large projects. Maybe 1.1 will change that. I might give it another shot, too!
I don't know how large each of these projects is, but a growing number of companies are using it for serious projects:
Iron.io: How We Went from 30 Servers to 2 with Go http://blog.iron.io/2013/03/how-we-went-from-30-servers-to-2...
Behind the Scenes: Big Data at Torbit http://torbit.com/blog/2013/02/19/big-data-at-torbit/
pool.ntp.org DNS server in Go http://news.ntppool.org/2012/10/new-dns-server.html
Juju at Canonical http://www.reddit.com/r/programming/comments/18atce/juju_can...
Go at bitly http://word.bitly.com/post/29550171827/go-go-gadget
CloudFlare blows hole in laws of Web physics with Go and Railgun http://arstechnica.com/information-technology/2013/02/cloudf...
dl.google.com now served by Go https://groups.google.com/forum/?fromgroups=#!topic/golang-n...
Go At Conformal https://www.cyphertite.com/blog.php?/archives/7-Go-at-Confor...
Go at Novartis https://plus.google.com/114945221884326152379/posts/d1SVaqkR...
Go at the BBC http://www.quora.com/Go-programming-language/Is-Google-Go-re...
Go at SoundCloud http://backstage.soundcloud.com/2012/07/go-at-soundcloud/
Go at CloudFlare http://blog.cloudflare.com/go-at-cloudflare
Go at Heroku http://blog.golang.org/2011/04/go-at-heroku.html
Building StatHat with Go http://blog.golang.org/2011/12/building-stathat-with-go.html
These are problems I have seen with larger java projects with unused imports, unused variables, library dependencies, long compile times, etc. I think that Go's niche is for extremely large projects, but it remains to be seen if it will work.
Your suspicions are well-founded! http://talks.golang.org/2012/splash.article
I think it's very D-unlike. It's very small and simple.
Want high performance and full control? Use C (or C++). Want your code to be easy to maintain by an average Joe? Use Java or C#. Want your code to be concise? Use Clojure. Want extreme typesafety? Use Haskell. Need to use both OOP and FP? Use Scala. What question to ask so the obvious answer would be "Use Go?"
I basically see it as a midpoint between C and python, that offers most advantages of both.
From C: Low memory use, fast execution, type safety/ compiled.
From python: Easy/fast to learn/read/write, no slow compile, GC, memory safety, good standard libraries
It also does concurrency better than python (/anything else?). What would you say better fits these criteria? Certainly not the JVM languages (memory) or Haskell (accessibility).
What question to ask so the obvious answer would
be "Use Go?"
Writing services in a SOA tech stack.Because that's exactly one of the niches of Java -- enterprise programming by average Joes. It was even a stated design goal of the language back in the day.
In languages with exceptions, potentially any function call you make could throw, and you don't know, because it could be 6 levels deep in the call stack. (Even Java's checked exceptions don't help, since someone down the line inevitably just rights "throws exception" and the screws everyone up the stack).
Go is really fast to pick up, it's pleasant to write code in, and yes... it's boring. I think that's it's biggest feature. It gets out of your way so you can produce a product. Why does the language need to be interesting? Isn't it more important that it can build interesting things quickly and reliably? Go does that.
Go does exception handling with panic, recover and its reflection syntax.
I don't understand the need to enforce the use of { } and that the if of for line must end with a {. I don't like this writing. My preferred syntax is the one of Pythons, which is the most concise and clear. It seem Go could have used : and indentation as in python instead of { }.
Another puzzling choice of Go is slicing which differ from Python's and D's. In Go slicing is limited by the capacity and not by the number of items it contains. Returning 0 as default value looks to me like an open door to silent bugs.
The way Go handles errors looks original and interesting, but I'm lacking experience to determine how it compares to exceptions from the usage perspective.
From what I saw, I would say that Go is a better C and D is a better C++ where better means also closer. As a consequence Go seams simpler than D to learn and use. Thus I expect we will see much more Go programmers than D programmers in the future. Simplicity has been proven many times to be trump.
This article explains the reasoning behind lots of Go's design choices: http://talks.golang.org/2012/splash.article
"Some observers objected to Go's C-like block structure with braces, preferring the use of spaces for indentation, in the style of Python or Haskell. However, we have had extensive experience tracking down build and test failures caused by cross-language builds where a Python snippet embedded in another language, for instance through a SWIG invocation, is subtly and invisibly broken by a change in the indentation of the surrounding code. Our position is therefore that, although spaces for indentation is nice for small programs, it doesn't scale well, and the bigger and more heterogeneous the code base, the more trouble it can cause. It is better to forgo convenience for safety and dependability, so Go has brace-bounded blocks."
That said, I don't consider this a convincing argument. They basically say "We had some problems in the past with embedding Python code in Java files". This is a very specific problem and I could think of at least 4 different specific solutions for this specific problem. I don't think this arguement can support very broad conclusions like "Spaces for indentation does not scale to big and heterogeneous code bases and compromises safety and dependability for convenience".
My qualm with Go here is that it does not enforce a consistent style. (note: I use Go quite frequently). Trailing semicolons, parentheses, curly braces should either be valid or invalid. There are instances in the languages where either is fine.
I think you misunderstand slicing. It's very similar to python's slices, except that python makes a copy of the list and Go does not. This is a really nice feature for reducing data copies.
The default values are very useful in many situations, and code is often designed around the fact that uninitialized variables have specific values.
As for error handling, Go's error handling is one of its biggest strengths, in my opinion. You never have to worry that your function will exit out in the middle unexpectedly. This is really great when dealing with third party libraries, since you don't have to know if something 6 levels deep is going to throw an exception... if something returns an error, you can deal with it right there. I find I write much more reliable code in Go, because error handling is so much simpler.
for p = initial; p.next != nil; p = p.next;
doSomething(p);
This is a whole class of pain I've had to debug before. Better to be explicit.I'm not really a fan of python indentation as I've had to clean up a couple of messes before.
Having done a lot of straight C programming in my life, the error handling in Go is very familiar. Most C code returns errors and doesn't use exceptions (though I have used setjmp()/longjmp() fairly successfully at times).
In practice, the code is more verbose with Go's style of returned errors, but requires you to think more explicitly about errors and recovery, resulting in potentially better code overall.
However, since Go doesn't have an RIAA like C++ and doesn't have "goto" like C, it makes cleaning up from errors more ugly and repetitious (and potentially error prone). File handling, in particular, is causing me headaches right now (getting files closed on errors). I am admittedly a Go newbie, so I may be missing some style that makes it cleaner.
file, err := os.Open(filename)
if err != nil {
// handle the error however you see fit
}
defer file.Close()
// continue working, knowing that file.Close() will be called when the surrounding function returns
See: http://golang.org/doc/effective_go.html#deferThe semi-colons are still there, but in most cases they can be inserted automatically when the program is being compiled.
1) Fast build times
2) Goroutines. If you've tried using any async library in Python or are waiting for Tulip to come into mainline Python around v3.4 - stop wasting your time. Goroutines along with channels just works (TM) and is unbelievably easy to use. No callbacks, no threadpools, no having to CTRL-C your way out of a bug. It's a pleasure to work with.
I'm looking for something for Go like PyGame is for Python. I like to get surfaces rendered on my screen in pretty much no time as I like to learn a language by doing simple graphical demos and experiment from there.
There are few SDL bindings for Go but none of them worked. One of them did work to some extent after a lot of tweaking without the help of many examples. I quit learning after I realized I'd have to learn more how the graphics bindings were written than how to program in Go.
OpenGL bindings are at https://github.com/go-gl
For 2D graphics there's promising project at https://github.com/skelterjohn/go.wde which provides interface that you can use together with http://golang.org/pkg/image/draw
(Issue worth noting is that none of the platforms specific parts in go.wde yet have hardware acceleration so it's not yet ready for game development etc. It's quite possible that that'll change in the future though :) )
And for ascii graphics we have https://github.com/nsf/termbox-go
There are bunch of other libraries as well but these are the ones that I'm more or less constantly using. go.wde is probably closest to what you were looking for but also the one that still requires hardware acceleration before it can properly be used as fast canvas for experimenting with games etc.
Note: None of these count as "standard library", all of them are third party projects by gophers around the world.
There are Go-bindings for SDL but I haven't tried is myself so I can't vouch for it. I have done some tests using the Go open-gl and glfw bindings though, and I encountered no problems when using them.
As for game frameworks, there's sadly nothing mature like pygame available, but I have seen a couple of such projects in development. One I came across recently and which also seems to be worked on in a regular fashion would be the GarageEngine,
https://github.com/vova616/GarageEngine
There are a couple of example videos on youtube:
http://www.youtube.com/watch?v=iMMbf6SRb9Q http://www.youtube.com/watch?v=BMRlY9dFVLg
Like you I would love to have a game framework for Go in the style of pygame/flashpunk/flixel/löve etc, but I feel hopeful that this will arrive in due time as Go picks up users.
Anyway, there are rumors that you can use OpenGL from Go, but I've never tried it.
and if you really want graphics, why not use Processing, OpenFrameworks, Cinder, or one of the languages supported by Unity? Go tends to really shine for writing servers. Of course, you could always use Go to write a game server for a multiplayer PyGame game.
On the other hand a more solid native 2d drawing library like java2d would be more welcome.
Weekend project #34532
Not hitting a DB. Benchmarked with 'ab -n 10000 -c 30 http://localhost:9000/some_action.
See also: https://github.com/davecheney/autobench BenchmarkHTTPClientServer 373216, 52646 -85.89%
bench old_ns/op new_ns/op delta
"BenchmarkHTTPClientServer 373216, 52646 -85.89%"
That bench is 7 times faster in Go 1.1 than 1.0.3.I don't see a tip in the hg repo for go1.1beta1. Anyone know what the right revision is? I'd rather install the known beta source than whatever's at the tip.
But as only fixes will be submitted between now and the 1.1 release, it's definitely better to use tip.
The only thing I'd strongly recommend is Gorilla Mux: http://www.gorillatoolkit.org/pkg/mux
And you can get an idea of how people build websites using Mux and Go by looking on github: https://github.com/jimmykuu/gopher
If you're very new to Go, then reading that last link repo you probably want to read these files in this order: https://github.com/jimmykuu/gopher/blob/master/src/server/ma... https://github.com/jimmykuu/gopher/blob/master/src/gopher/se... https://github.com/jimmykuu/gopher/blob/master/src/gopher/ur... and then to take a look at the files in this folder for the handlers and html/template calling: https://github.com/jimmykuu/gopher/tree/master/src/gopher
go get code.google.com/p/go.net/websocket
The html processing lives in there too: go get code.google.com/p/go.net/html
If you see people refer to go.net, they mean that repo.Gorilla toolkit is also very neat, but it's a handy tool-box for web work, rather than a kitchen-sink framework.
source: http://benchmarksgame.alioth.debian.org/u32q/benchmark.php?t...
I know of Collin VanDyck's web service showdown (http://boundary.com/blog/2012/09/17/comparing-go-and-java-pa...) which showed that Java had lower latency and higher throughput for highly concurrent tasks based on a very simple code base, but net/http performance in Go 1.0 wasn't a high priority. It seems that it has since been bumped up the priority list and a lot of work has been going on (https://groups.google.com/d/topic/golang-nuts/zeLMYnjO_JA/di...).
The thing is, Go isn't just for writing web apps. If you have a look at some of the real world use cases for Go (there's a list in another comment here somewhere) you'll notice that these aren't just web apps.
Every bit of Go code I've written (web app, mp3 database generator, encryption library) has been blisteringly fast, and it seems Go 1.1 will bring substantial performance improvements again.
Oh, and I didn't down-vote you, I don't yet have that privilege.
Also, don't forget at the time of this posting that page is showing Go 1.0.3 not 1.1 beta.
Yeah, it's pretty much the other way now.
Go maps very closely to how I think about programming. It has more useful features than other languages, like channels, slices, and range. Yet despite this it is a beautifully simple language. It has fewer keywords than C and you can express the same operations with less code.
Once you're beyond just plain CRUD to the point where the language you're using matters more than how fast you can get going with defaults, then you might like Go more (or less) than Ruby/Python.
However, as you can see, it's not too difficult to write a basic CRUD app with authentication, even if you're starting completely from scratch (which you don't have to; I did it more as a learning exercise).
I disagree with jbooth; I find Go's templating language to be incredibly mature, and I also find it much easier to develop with gorilla than something like Flask, if for no other reason than the static compilation and incredibly thorough code analysis/other checking done at compile-time (unused lvalues, etc.)
Here are some of mine, that I turned into Go code: (restricted to "week long hacking" or less)
A simple blog application.
A command that when run, sends the output of other commands to your email.
An image viewer.
A simpler interface to `xrandr`.
A parser for the new TOML configuration format.
Or, you could pick a small program that you wrote in another language and port it.If/when they find a solution that fits their strict criteria, it in all likelihood will require breaking changes to the Go language, and the point of having the 1.x series was a promise that this would not happen.
If you want other types with generic functionality (e.g. caches) that perform well (interface{} does not), then you have to use external code generators.