Start Programming with Google Go

Go Google, Go Programming - Mark Alexander Bain
Go Google, Go Programming - Mark Alexander Bain
No-one searches on the Internet any more - they Google. And Google is about to have a new meaning as a programming language with the introduction of Go!

As a programmer (and, let's be honest, as a writer) I'm always on the look out for new programming languages. Now finally, after a 10 year wait, a new one has turned up. And from a surprising source (or maybe not so surprising if you think about it). That new programming language is Google's Go.

Google Go is loosely based on the syntax of C and Python (after all, why mess with something that works?) and has been built to provide faster compilation times and greater efficiency. They have realised that computing power has moved forward a long way in the past decade but programming languages have not moved forward with it. Hence Google Go.

Unfortunately (for some) Go is only available for Linux and Mac computers at the moment. However, anyone sensible enough to be developing on either of those platforms can be up and running with Google Go in just a few minutes.

Installing Google Go

Installing Go is a simple enough process. In my case that installation is on an Acer Aspire One running Ubuntu's Lucid Lynx and the first steps are, of course, to install any dependencies using apt-get:

apt-get install python-setuptools python-dev build-essential

Again that's for an Ubuntu system, they may not be needed on other systems or may already be installed (as they were on my pc). The next piece of software probably won't be there but is required:

sudo easy_install mercurial

Mercurial is a cross-platform revision control tool and, with that in place, the current version of Go can be downloaded:

hg clone -r release https://go.googlecode.com/hg/ go

Go will be downloaded into a folder named (unsurprisingly) "go" and then it's just a matter of compiling the compiler:

cd go/src

./all.bash

This is the time to go and make a cup of tea or coffee (Lidl's Bellarom Gold 100% Arabica Filter Coffee is a particularly good choice at this point) after which the installation process will (hopefully) be displaying a simple but encouraging message:

You need to add ~/go/bin to your $PATH.

And now, with our lovely cup of coffee, we're ready to create that most important of all applications - the "Hello, World" application:

A Simple Google Go Application

All that's required is a standard text editor (my personal favorite being Gedit) and then some simple code that any programmer will understand:

  1. package main
  2. import "fmt"
  3. func main() {
  4. fmt.Printf("hello, world\n")
  5. }

If this is saved as "hello.g" then we're ready to compile. The actual compilation varies slightly according to the system architecture. I have a computer with the 386 architecture and so my compile instructions are:

  1. 8g hello.go
  2. 8l hello.8

If I had an arm architecture then I would use 5g and 5l or 6g and 6l for the amd64. The executable will be 8.out, 5.out or 6.out (again depending on the architecture). And so, from now on, instead of search we will Google and instead of program we will just Go!

Mark Alexander Bain - Mark Alexander Bain is a writer, Mo Bro and consultant for all aspects of software development at dsquared. He has also written regularly ...

rss
Advertisement
Advertisement
Advertisement