Writing Ruby extensions in Go – an in depth review

For a very long time the only way to extend Ruby with native estensions has been using C.
I don’t have the numbers with me, but I guess C is not the first choice for Ruby programmers when they have to pick up a secondary/complentary language.
So I started investigating the possibility of writing them in other languages, taking advantage of the favorable moment: in the past 3-4 years we had an explosion of new languages that compile down to native code and can be easily used to produce a C equivalent shared library that Ruby can pick up and load.

My main goal was to find languages that a Ruby programmer would understand effortlessly or with a minimum investment.
This first episode will focus on Go.

Continue reading “Writing Ruby extensions in Go – an in depth review”

I tried Go and I liked it

I tried Go and I liked it

Gopher in all of its glory

Say hello to Gopher.
Gopher is the mascotte of a new language from Google, called Go, with the capital G.
Not a very clever name from a search engine company, if you ask me, but that’s probably the only bad thing you will hear about it.

Hint: use the word golang to search on Google

A brief introduction

Created inside Google by Ken Thompson and Rob Pike, fathers of Unix and UTF-8, to overcome the limitations of C++ (compile times being the most annoying), Go is a concurrent, garbage-collected language with fast compilation.

Its real strength is just simplicity.
As Rob Pike once said, less is exponentially more and I strongly agree with him.

Features

  • blazing fast compilation speed
  • statically compiled binaries (the result is a single binary with no external dependencies)
  • type safe, statically typed with some type inference support. More errors get caught at compile time, less time is spent debugging
  • garbage collected with support for pointers, but no pointer arithmetics (for safety and good health of programmers minds).
  • strict compiler: you can’t declare a variable or import a package without using it
  • concurrency and parallelism through goroutines. Goroutines are one of the peculiarities of Go, they are a cheap, lightweight construct built on top of threads, that run concurrently with other goroutines. If you have more than one core processor, they also run in parallel, in a completely transparent way for the programmer. Communication is managed sending messages through channels which are basically type safe queues.
  • Object orientation but no classes. Any type can be an object.
  • No type inheritance in favour of composition and duck typing. IS-A relationships are banned!
  • multiple return values
  • rich standard library.
  • a powerful set of command line tools including one to enforce coding conventions and one for automatic code documentation.
    Many IDE that support Go, launch gofmt just before save, to ensure that every Go file obey the rules.
  • last, but not least, cross compiling. Go compiler can create binaries for platforms/architectures different from the one it is running, provided the platform is supported.

Continue reading “I tried Go and I liked it”