My name is Ken and I’m a geek. Like most geeks I like to stay up to date with the latest technologies, and normally try to find some excuse to play with them. As a dotCloud engineer I take advantage of our once a month hackdays to do just this.
One of the technologies I have been hearing a lot about lately is a new programming language called Go.
On the Go website it says “Go is an open source programming environment that makes it easy to build simple, reliable, and efficient software.” At first pass that sounds like a lot of programming languages, so what makes it better than the rest, and why is this so special?
To answer those questions, I’m going to steal some sections from the Go FAQ.
Go is a concurrent, garbage-collected language with fast compilation. It was started at Google and was released to the public on November 10, 2009.
Features of Go
- It is possible to compile a large Go program in a few seconds on a single computer.
- Go provides a model for software construction that makes dependency analysis easy and avoids much of the overhead of C-style include files and libraries.
- Go’s type system has no hierarchy, so no time is spent defining the relationships between types. Also, although Go has static types the language attempts to make types feel lighter weight than in typical OO languages.
- Go is fully garbage-collected and provides fundamental support for concurrent execution and communication.
By its design, Go proposes an approach for the construction of system software on multicore machines.
Typical Go App
If you have never seen a Go program before, here is the typical Hello World application written in Go.
Looking at the code it is pretty straightforward. If it wasn’t for the curly brackets it almost looks like Python.
If you want to learn more about Go, I recommend their excellent tutorial http://tour.golang.org. I also did a quick search on amazon and it looks like there are already a number of Go books. So pick one up today, and start learning.
Learning Go on dotCloud
We are starting to use Go on a few internal projects at dotCloud. I like what I see so far, but before I get too ahead of myself, I still have a lot to learn. I personally find the best way to learn is to have a small, real world, non-critical project that you can use as your guinea pig.
Reading books and going through tutorials is a good place to start, but it’s a lot like high school physics, when you ignore friction, wind resistance and gravity. Once you start doing real world problems which include those variables, things never go smooth the first time.
That is why it is always best to get your hands dirty on a real project as soon as possible. dotCloud’s free sandbox apps are perfect for this.
I’m not sure about you, but a lot of the projects that I work on lately are web-based. I was sad to find out that there were not many options for hosting Go applications. It seems you could run your own server (VPS, etc) or you could deploy to Google App Engine.
One of the many advantages of working for dotCloud is having access to this awesome deployment platform, where I’m like a kid in a candy shop. I can take these different services, write some code and easily deploy them to dotCloud, all without breaking a sweat.
Last Friday we had a hackday at dotCloud, where everyone takes the day off from their normal projects and we can work on anything we want. I took this time, to work on a Go on dotCloud custom service. It is still very early, but it allows you deploy your Go applications to dotCloud as easily as all of our other services.
Try it out on dotCloud
I have put the code up on github so that everyone can use it, and submit pull requests. It is still very early beta, but I welcome everyone to try it out, and please let me know what you think, good or bad. If you have a suggestion on how to make it better, feel free to submit pull requests and issues.
Using it is pretty straightforward. Assuming you already have a FREE dotCloud account, you just need to follow these steps.
- Create a new application
$ dotcloud create -f sandbox mygoapp
- Fork my github repo, and then clone it.
$ git clone git://github.com/kencochrane/golang-on-dotcloud.git
- Add your code in the src directory.
- Edit the dotcloud.yml
- Change the build_package config variable, to the name of your GO package
- Change the processes so that you can run the correct processes
- Add or remove ports depending on your application needs.
- Push the application
$ dotcloud push mygoapp .
That should be about it. Best of all you can do all of this for FREE since dotCloud doesn’t charge for services in the Sandbox. So deploy as many times as you like, and let me know if you have any questions or problems.
Coming from a Python background, I am most interested in the fact that Go is a fast compiled language with concurrency built-in. I don’t think it will replace Python as my go-to language, but when I need something small and fast with concurrency, it is nice to know there is another option at my disposal.
I’m looking for new ideas for my next hackday, if you have any suggestions, please let me know.