With a myriad of programming languages available out there, developers often face tough decisions in choosing the language that balances best between a number of factors, which can range from compatibility to ease of use. In the last few years, a number of developers are making the switch from more established languages and turning to a relative newcomer: Google’s Go — a statically typed language that uses a syntax similar to that of C. As we’ve previously heard before, these programmers are speaking out about why they are choosing Go: due to its better performance, simplicity, and its ability to execute multiple computations simultaneously, as well as for other reasons.
One Rubyist’s Journey from Ruby to Go
In this second talk from GopherCon India, Mike Gehard of Pivotal Labs relates the story of his journey from programming almost exclusively in Ruby and switching to Go, and his tips on making a transition, based on his experiences of learning the syntax and idioms of a new language.
Gehard tips are to learn the vocabulary and syntax of a language — both are relatively easy, compared to learning a language’s idioms. He notes that Ruby’s specification documents are much more complex and difficult to understand, compared to Go’s specs, which currently number around only 50 pages.
Gehard explains that knowing how idioms work are key to communicating effectively in Go. Idioms are a special kind of phrasing, or a peculiarity. Gehard postulates that writing idiomatic code makes using a language easier: if you know what the idioms look like, you can produce code much more effectively, and it allows others to understand your code more easily.
In Ruby, interfaces are never defined or passed around, but with Go, everything has interfaces. Go has two interfaces: a reader and a closer. If you want to use both, you compose and reuse interfaces. Another interesting experiment to try with Go: instead of writing objects, write structs, and functions that operate on the structs. Do not attach methods to your structs and see what happens — experimentation is key to learning the language and having fun.
Featured image via Flickr Creative Commons.
Pivotal Labs is owned by Pivotal, a sponsor of The New Stack.
The New Stack is a wholly owned subsidiary of Insight Partners. TNS owner Insight Partners is an investor in the following companies: Docker, Bit.