8 ms·
My day job involves working with Java and C++ on 10+ year old systems. All of my hobby or side projects are in Go these days with occasional diversions into has
by zaphar 14y ago
My day job involves working with Java and C++ on 10+ year old systems. All of my hobby or side projects are in Go these days with occasional diversions into haskell, ML or various Lisps.
So I'll try to impart some understanding of why I would switch to Go from Java or C++.
First lets get some things out of the way. Go is fast enough and getting faster very quickly and it definitely has a smaller memory footprint. So when compared to java and C++ in those dimensions it holds up just fine but that might not be enough to sway someone over to the Go camp.
It's about what else Go has:
* Go is a batteries included language. The stdlib has almost everything you need to get started much like python does.
* Go is fast for development. I mean really fast. I mean like using Lisp in a REPL fast (almost). I really can't express how fast it's development speed is adequately just trust me its really really fast. This is not just about how fast it compiles although that's part of it. (I've literally been able to write, compile, and run a go "script" faster than an equivalent python script.)
* Go makes concurrency easy to get right. I haven't seen any other language get this so right since Erlang.
* Go is concise. There is no wasted typing. It's easy to read and it's easy to write. Every feature of the language is orthoganal. And it tells you quickly when you've done it wrong.
* Go does OO right. Code reuse through composition not inheritance. Polymorphism through interfaces not inheritance. I never have to worry about it with Go. C++ or java? yeah I've got some inheritance related war stories there.
All of these things exist in other languages but Go is the only language where they all exist together. This is reason enough to switch to Go but there's more.
Go's future is bright. I don't say this because it has celebrity tech people behind it. I say this because the foundation they are laying demonstrates the core team knows what they are doing. Here's some examples.
* Go comes with all the tools you need to programmatically understand Go code. Parser, Type checking, Static analysis is all available via the stdlib. As a result GoCode which adds IDE functionality to the EDITOR of your choice came on the scene very quickly. Java doesn't have this. C++ doesn't have this. Go made it possible to create an IDE as a service with minimal effort. Besides Gocode you also have gofmt. Never worry about code formatting again. gofmt will reformat it for you and it will never break your code. It's 100% safe. I am aware of no other language excepting lisp with this functionality.
Lastly I want to address your "a lot less powerful" comment. I think it's false. In now way is Go less powerful than Java. It's fast enough to be in the same league as java. It has a lower memory footprint than java. It compiles faster than java. And the language itself is if anything more powerful and expressive than java. It has closures, It has interfaces that are just as typesafe and yet easier to use than java.
In fact I'll sum it up in one word: Go is relaxing.
- tocomment 14y agoHow did you write a go script faster than a python script? That sounds intriguing.
- zaphar 14y agoedit script in vim. use :!go run % It will compile and run the script so fast you will swear it was an interpreted language except it runs way faster than an interpreted language.
- oinksoft 14y agoYou have to write it first for the Go example (:w | !go run %). For Python and most interpreted languages you can simply do :w !python.
- jlgreco 14y agoThe time it takes to 'go run' a go program is about the same as the time it takes to run a python program. If you are able to write Go code faster than Python code (that is the important "if". I can, some cannot. It's a personal thing.), then Go will be faster than python.
- pron 14y agoOh, I don't doubt many things can be done much better in other languages than Java, only why stop at Go? Clojure pretty much hits every single one of your requirements, it's more modern and expressive than Go, gets concurrency better, and it's about as slower than Go as Go is slower than Java -- and getting faster. Also, you don't have to give up the monitoring and instrumentation the JVM gives you, as well as the vast Java ecosystem. I'm not saying Go isn't better than Java -- I'm sure it is. My main point is this: if I want to relax, there are more relaxing languages than Go; if I really need JVM-like performance, I'd rather go with Java and not relax as much; and if I need both -- there's Clojure, Scala, Kotlin (soon). This leaves one point: RAM footprint, which I'll concede. But stacking that against the JVM's monitoring and large ecosystem, I'll take the JVM any day. So, Go is nice. Really nice. But not nearly nice enough to even consider abandoning the JVM (unless you're memory-constrained, in which case the JVM was never an option). Also: > Go makes concurrency easy to get right. I haven't seen any other language get this so right since Erlang. I'm not so sure about that. If I'm not mistaken, most Go objects are mutable and can still be passed as messages. > Go comes with all the tools you need to programmatically understand Go code... Java doesn't have this. It does since Java 6: http://docs.oracle.com/javase/6/docs/jdk/api/javac/tree/index.html http://docs.oracle.com/javase/6/docs/jdk/api/javac/tree/inde...