Wednesday 29 September 2010

In which I Go

I think I mentioned that I've decided to teach myself Go, Google's new programming language. I've been doing just that, reading tutorials, style guides, tips and package documentation. It's good stuff, I'm very impressed by the design of this language.

I particularly like its clear support for concurrency, as well as the typing system. I feel that I'm learning fast, although interactions on the golang-nuts mailing list help me see that there are still some concepts that I need to learn or brush up on. I think this comes of spending the last few years coding mostly in PHP.

Now the thing about Go is that it lends itself naturally to use on servers, having some nice libraries for common server operations. That being the case I foresee using it in that context, so I set out in search of a database library.

That's one area where the core libraries seem oddly lacking so far, although that may change. However, a Go community member has developed a package called GoMySQL, which I believe will suit me quite well. I've forked the project on GitHub so that I can make any changes I need as they come up, as well as additions.

I'm an Object Oriented programmer, by education. I studied C++ mainly where I became fond of creating classes to represent concepts in my code. Go doesn't have classes, but it is object oriented. It's a departure and an interesting one, in which structs are used where we need data types, but where we need types that offer a clearly defined interface that is exactly what we write, an interface.

It serves to separate the two aspects of a class, its members and methods. Both exist in Go, but they're not so tightly bound. The same methods may apply to structs with different sets of members. A single struct type, with a single set of members, may implement multiple interfaces' methods.

In practical terms this frees design from the tyranny of type hierarchy. A type may be defined that is equally a Reader and a Writer, these being predefined interfaces. It's not a Writer derived from a Reader, or vice versa. It doesn't have both Reader and Writer as parent types. No, it simply is both, as much one as it is the other. It's smooth.

There's a lot more to it, with slices and channels and goroutines. It's all pretty cool stuff, but those are the bits that I felt like mentioning. There may be more as I continue to learn.

I have to say, as well, that I think I probably will work on that game I mentioned. It'll be slow, occasional effort, but Go looks well suited to the server portion of the system, so that's something I intend to do.

No comments:

Post a Comment