Ayende @ Rahien

My name is Oren Eini
Founder of Hibernating Rhinos LTD and RavenDB.
You can reach me by phone or email:


+972 52-548-6969

, @ Q c

Posts: 6,130 | Comments: 45,558

filter by tags archive

JAOOThe Go Programming Language

time to read 5 min | 845 words

Currently sitting in the Go language keynote in JAOO.

Go was created to handle Google needs:

  • Compilation speed
  • Efficient
  • Fit for the current set of challenges we face

Go is meant to be Simple, Orthogonal, Succinct. Use C syntax, but leave a lot of complexity behind.

This make sense, because C/C++ is horrible for a lot of reasons, because of complexity added to it over the years. Actually, the major problem is that C/C++ mindset are literally designed for a different era. Take into account how long it can take to build a C++ application (I have seen no too big apps that had half an hour build times!), and you can figure out why Google wanted to have a better model.

Nice quotes:

  • Programming shouldn’t be a game of Simon’s Says
  • Difference between seat belts & training wheels – I am going to use that a lot.

I find Go’s types annoying:

  • [variable name] [variable type] vs. [variable type] [variable name]
  • And []int vs. int[]

I like the fact that is uses garage collection in native code, especially since if you reference a variable (including local) it will live as long as it has a reference to. Which is a common mistake in C.

It also have the notion of deferring code. This is similar to how you can use RAII in C++, but much more explicit, which is good, because RAII is always tricky. It very cleanly deals with the need to dispose things.

All methods looks like extension methods. Data is held in structures, not in classes. There is support for embedding structures inside one another, but Go isn’t an OO language.

Interfaces work for all types, and interfaces are satisfied implicitly! Much easier to work, think about this like super dynamic interfaces, but strong typed. Implies that we can retrofit things afterward.

Error handling is important, and one of the major reasons that I moved from C++ to .NET. Go have two modes, the first is error codes, which they use for most errors. This is especially nice since Go have multiple return values, so it is very simple to use. But it also have the notion of panics, which are similar to exceptions. Let us take a look at the following test code:

package main

func test() {

func main() {

Which generate the following panic:

panic: ayende

panic PC=0x2ab34dd47040
runtime.panic+0xb2 /sandbox/go/src/pkg/runtime/proc.c:1020
    runtime.panic(0x2ab300000000, 0x2ab34dd470a0)
main.test+0x47 /tmp/gosandbox-a9aaff6c_68e6b411_26fb5255_aa397bb1_6299a954/prog.go:5
main.main+0x18 /tmp/gosandbox-a9aaff6c_68e6b411_26fb5255_aa397bb1_6299a954/prog.go:8
mainstart+0xf /sandbox/go/src/pkg/runtime/amd64/asm.s:78
goexit /sandbox/go/src/pkg/runtime/proc.c:145

I got my stack trace, so everything is good. Error handling is more tricky. There isn’t a notion of try/catch, because panics aren’t really exceptions, but you can recover from panics:

package main
import ( 
func badCall() {

func test() {
   defer func() { 
    if e := recover(); e != nil {
       fmt.Printf("Panicing %s\r\n", e);
   fmt.Printf("After bad call\r\n");

func main() {
   fmt.Printf("Calling test\r\n");
   fmt.Printf("Test completed\r\n");

Which will result in the following output:

Calling test
Panicing ayende
Test completed

All in all, if I need to write native code, I’ll probably go with Go instead of C now. Especially since the ideas that it have about multi threading are so compelling. I just wish that the windows port would be completed soon.

More posts in "JAOO" series:

  1. (06 Oct 2010) The Go Programming Language
  2. (20 Oct 2009) More on Evolving the Key/Value Programming Model to a Higher Level from Billy Newport
  3. (07 Oct 2009) OR/M += 2
  4. (05 Oct 2009) Evolving the Key/Value Programming Model to a Higher Level
  5. (05 Oct 2009) Working Effectively with Legacy Code 2 – Michael Feathers



I would still go with C++ because you will not find much Go tooling and libs. I started programming in Visual C++ so I know to a certain extent how painful C can be. Still, there are many patterns to help you out.

Demis Bellot

I have also spent some time playing with Go unfortunately the lack of proper exception handling and generics is a deal breaker for me - string handling is also not so great.

I really like their non-intrusive interface/type system - I hope C# will consider adopting something similar in future versions. The built-in CSP style concurrency also shows a lot of promise. However a lot of the areas where I thought about using go, I can also use node.js for - which is my current preference.

I also agree that it would be my preferred native language, however the next language on my tech radar is Scala on the JVM.

Andrey Shchekin

The syntax looks ugly for me, and after being shown D by students, I think I will consider D for native code, instead of C++. However I am not sure abut its parallel capabilities.


typo: garage collection.


'An array of ints' transformed into '[]int'? Nice :)



Checkout D programing language from digital mars, It has a more familiar feel especially coming from c#


I agree with a lot of your points. I don't like that weird way to type stuff, and I especially hate the exception handling. Overall it looks like a very nice language though.


The idea of using 'panic' for error handling looks very strange. Traditionally panic is an unrecoverable disaster when the program needs to terminate


Statically typed languages are a pain in the ass, dynamic is the future.

Matt Freeman

Google are really big on Go. They have versions for their flagship Android platform and their cloud App Engine. In addition there are many details including technical white papers on how Google is using Go internally for most of their native processing. Third party companies are actively investing in tools and IDE support. And the most popular platform Windows was supported very early on. The community is also thriving. Checkout the IT section on Amazon to, Go has the top 3 of the top 100 IT books.

Comment preview

Comments have been closed on this topic.


  1. How to waste CPU and kill your disk by scaling 100 million inefficiently - 5 hours from now
  2. RavenDB Conference 2016–Slides - about one day from now

There are posts all the way to Jun 01, 2016


  1. The design of RavenDB 4.0 (14):
    26 May 2016 - The client side
  2. RavenDB 3.5 whirl wind tour (14):
    25 May 2016 - Got anything to declare, ya smuggler?
  3. Tasks for the new comer (2):
    15 Apr 2016 - Quartz.NET with RavenDB
  4. Code through the looking glass (5):
    18 Mar 2016 - And a linear search to rule them
  5. Find the bug (8):
    29 Feb 2016 - When you can't rely on your own identity
View all series


Main feed Feed Stats
Comments feed   Comments Feed Stats