Tuesday, January 18, 2011

c, python, go, vala, mono - what go has to offer

If you are on a Debian / Ubuntu system and just want to write a very short go program [ to experiment with syntax ] then:
  apt-get install gccgo

If you are on a Debian / Ubuntu system and want to test out programs that conform to Go 1.0 then:
  apt-get install golang-go

If you are writing more involved programs and have already mastered basic Go syntax, then Debian 8 (jessie) has Go 1.3 available

You can always download a source package from golang.org directly also

If you want to experiment without doing any of the above then you can write and execute Go code directly at play.golang.org

If you came here looking to install Docker, then you should know that docker requires Go 1.1 or newer, however pre-rolled packages for Docker are available and do not require a separate local install of Go.
  apt-get install lxc-docker

( lxc-docker is available once you have added docker own deb repository )

Now back to the article ...

The ordering in the article title was deliberate, and represents how I feel personally about those languages, based on a cursory look at the licensing and patent situation for each.

Here is a patent statement about Go which is a recent language from Google:

So how does go compare in syntax with the other languages?

Here i show a variable definition as this can be a useful first guess as to how high or low level the language is:

var a uint64 = 1;

a := uint64(1);

Focusing on the first form, this looks to be say 'who then what' rather than the C order which would be more like 'what then who'

Go is not designed for people who are entirely happy using ANSI C, if you were entirely happy, then there would be no reason to hanker after constructs from other languages (Cython, Python, C++, whatever).

Go is braces friendly, and semicolon warm:

If you hate braces, then you are probably not a Java or C# coder, and Go will not interest you either.

I say semicolon 'warm'. Here are the words from the Go site:
You might have noticed that our program has no semicolons. In Go code, the only place you typically see semicolons is separating the clauses of for loops and the like; they are not necessary after every statement.
In fact, what happens is that the formal language uses semicolons, much as in C or Java, but they are inserted automatically at the end of every line that looks like the end of a statement. You don't need to type them yourself.
Seems that the language does use semicolons, but providing you use braces as intended, then you can leave it to the language to insert them for you. Yey \o/

Here is that said in Wikipedia words:
automatic semicolon insertion feature requires that opening braces not be placed on their own lines

So I began with a point about the patent situation for Go...
now what about the license?

Go has a BSD style license and you can find the text here:

Now here is the question I always ask:- Are Debian, FSF*, and Red Hat happy to package / distribute the go binaries provided by Google?

(*In the case of the FSF it is more likely that they will be approached for comment or give an opinion rather than necessarily acting as distributor)

Well there has been some work to add Go compilation to gcc, which compiling from source would have you typing:

or just maybe install gccgo direct from your repository ... here for Debian.

Here is where things are with Red Hat / Fedora ... some clarification is required before Go is packaged as an rpm.

( I will not play the game of Debian versus Red Hat in terms of approval, I value both opinions in conjunction with the fsf, in order to feel that others with more experience have okayed the thing. There was a time for me when Debian's say so was the key indicator of such things, but with go-oo.org code and mono in debian, I prefer multiple checks these days )

So where does that leave me in regard to 'Go', and will I learn to program in that language?

Having spent the last few months hopping between C and Python, and checked the patent and license situation, Go / Rest / Nimbus are languages I may never need now that Asyncio is part of Python3 standard library.

Above Go in my list of languages/frameworks to learn would be Cython and Django, by which time, Go may have moved up into the top 20 of Dr Dobbs / PyPL popularity lists.

1 comment:

Gary said...

My understanding about Go and the runtime/compilation is that there are two ways:

(1) Use gcc4.6 gccgo

(2) Use google supplied go

The second option is perhaps a very fast moving target, as go itself is in heavy development.

Folks who run debian or want to learn go against a fixed language spec, might want to use gccgo

Here is a debian bug that might explain why gccgo is in experimental ahead of google own supplied go:

Personally I would recommend gccgo, at least until the 'network required' thing is explained a bit more fully in bug #574371

Finally some collected comments from around the web about Google Go:

"Go doesn't produce bytecode to run in a virtual machine. In this respect, it's more like C or C++"

"A basic garbage collector was added to gccgo"

Handy benchmark for Go here

And the thoughts of akamaka which I reproduce here:

I'd have to disagree with the title "Python meets C++". There's very few features that have been brought over from either of those languages.

It looks like C with some very carefully chosen additions: memory safety, concurrency and maps.