Skip to content

Learning Go – Miniblog #1

January 8, 2013


My New Year’s resolution to really learn Haskell seems to have stalled (already!), so I thought I’d write a few very short articles about my sporadic attempts to learn the Go programming language. Don’t expect these to go into any great depth, and definitely don’t expect them to form a great and comprehensive tutorial! All articles will be Windows-only.


Installing was easy. I followed the instructions here, using the ZIP archive method. I installed, as is my practice, into a subdirectory in my C:\prog directory – I always try to use directory names with no spaces in them, so everything ended up in C:\prog\go. I then used the excellent Rapid Environment Editor to add C:\prog\go\bin to my PATH variable and to create a new environment variable called GOROOT which contained the value C:\prog\go. I also copied the go\misc\syntax\go.vim file into my Vim installation to enable syntax highlighting with my favourite editor. I then started up a new command-line shell (important to do this), typed go and was pleased to see the go tools were recognised.

Hello World

Of course, the first program anyone writes is one that displays “hello world” in some form, and here’s my first attempt (which is modified from the example in the Go documentation):

package main
import "fmt"
func main() {
    fmt.Printf("hello world from go\n")

I saved this as hello.go, and then compiled and ran it like this:

go run hello.go

with the expected results. Running like this doesn’t permanently produce an executable, and a bit of poking around lead me to try:

go build hello.go

Which produced an .EXE file with the somewhat staggering size of over a megabyte. I don’t normally care too much about such things, but both C and C++ (using GCC) produced executables of sizes around 75K. Maybe I can reduce this later?


That’s all for now – next step; decide what I am going to build with this new language.


From → golang

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: