0
0
Fork 0
zblog/content/post/108.md

99 lines
3.7 KiB
Markdown

+++
title = "playing with go"
date = "2014-04-04T22:39:45+00:00"
author = "Gibheer"
draft = false
+++
For some weeks now I have been playing with Go, a programming language developed
with support from google. I'm not really sure yet, if I like it or not.
The ugly things first - so that the nice things can be enjoyed longer.
Gos package management is probably one of the worst points of the language. It
has an included system to load code from any repository system, but everything
has to be versioned. The weird thing is that they forgot to make it possible to
pin the dependencies to a specific version. Some projects are on the way to
implement this feature, but it will probably take some time.
What I also miss a shell to test code and just try stuff. Go is a language which
is compiled. I really like it for small code spikes, calculations and the like.
I really hope they will include it sometime in the future, but I doubt it.
With that comes also a very strict project directory structure, which makes it
nearly impossible to just open a project and code away. One has to move into
the project structure.
The naming of functions and variables is strict too. Everything is bound to the
package namespace by default. If the variable, type or function begins with a
capital letter, it means that the object is exported and can be used from other
packages.
// a public function
func FooBar() {
}
// not a public function
func fooBar() {
}
Coming from other programming languages, it might be a bit irritating and I still
don't really like the strictness, but my hands learned the lesson and mostly
capitalize it for me.
Now the most interesting part for me is, that I can use Go very easily. I have
to look for much of the functions, but the syntax is very easy to learn. Just
for fun I built a small cassandra benchmark in a couple of hours and it works
very nice.
After some adjustments it even ran in parallel and is now stressing a cassandra
cluster for more than 3 weeks. That was a very nice experience.
Starting a thread in Go is surprisingly easy. There is nothing much needed to
get it started.
go function(arg2, arg2)
It is really nice to just include a small two letter command to get the function
to run in parallel.
Go also includes a feature I wished for some time in Ruby. Here is an example
of what I mean
def foo(arg1)
return unless arg1.respond_to?(:bar)
do_stuff
end
What this function does is test the argument for a specific method. Essentially
it is an interface without a name. For some time I found that pretty nice to
ask for methods instead of some weird name someone put behind the class name.
The Go designers found another way for the same problem. They called them
also interfaces, but they work a bit differently. The same example, but this
time in Go
type Barer interface {
func Bar()
}
func foo(b Bar) {
do_stuff
}
In Go, we give our method constraint a name and use that in the function
definition. But instead of adding the name to the struct or class like in Java,
only the method has to be implemented and the compiler takes care of the rest.
But the biggest improvement for me is the tooling around Go. They deliver it
with a formatting tool, a documentation and a test tool. And everything works
blazingly fast. Even the compiler can run in mere seconds instead of minutes.
It actually makes fun to have such a fast feedback cycle with a compiled
language.
So for me, Go is definitely an interesting but not perfect project. The language
definition is great and the tooling is good. But the strict and weird project
directory structure and project management is currently a big problem for me.
I hope they get that figured out and then I will gladly use Go for some stuff.