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.

Why One Front-End Developer Chose Go Over JavaScript

In a talk last week at GopherCon India, Denver, Colorado-based front-end developer Julia Poladsky elaborated on why Go is a better design language than JavaScript.

Poladsky explains that though it’s easy to get started with JavaScript and write service-side code for node or front-end applications, with upcoming editions ES6 and ES7, JavaScript will be confined as new language features are added.

Some notable features of JavaScript is that it can easily handle functions, object literals and dynamic typing. On the other hand, JavaScript has easily declared globals, where everything is dumped into the same global space, which can be difficult to distinguish, all of which can trip up the rookie developer.

Poladsky sees Go as the next step in the evolution of programming languages. Go has, and builds upon, all the major advantages of JavaScript, and yet is more straightforward. For example, like JavaScript, Go’s functions are also first-class citizens. There’s lexical scoping in Go, but it includes blocks. You can also do closures with Go, and implement create methods on different types. But since Go is statically typed, it’s a bit different: it supports type parameters, type returns and multiple returns.

Other notable similarities are JavaScript’s asynchronous functions compared with Go’s concurrency, which is simple to understand. Go is “garbage-collected,” unlike other statically typed languages — there’s less worry about memory management, and according to Poladsky, Go has “good error handling.”

Another notable difference is that instead of JavaScript’s infinite arguments, Go has something called “splats,” which may possibly be implemented in JavaScript ES6. Also, in comparison to JavaScript, Go complier errors may seem intimidating at first, but it helps developers to learn and understand the language more thoroughly. While JavaScript has prototypical inheritance, Go has composition, which can be implemented with interfaces. Go’s composition is “safe, comfortable and explicit,” as it can solve complex relationships that classical inheritance cannot. Go’s straightforward, easy-to-understand nature ultimately compels developers to write explicit code that is clear, objective, easy to maintain and lets the developer know exactly what the code is doing.

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.

Coming from Ruby, Gehard recommends starting with a clean slate, with no preconceptions of how a new language should be written, because Go is unlike object-oriented programming languages like Ruby, Java and JavaScript. Go has no inheritance; it uses composition, and Go has a lightweight type hierarchy, unlike Ruby. Gehard refers to Nathan Youngman’s articles on Go: here and here.

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.

Gehard recommends studying concurrency models, but also using concurrency sparingly in Go. Finally, Gehard gives some other tidbits: performance is not the only factor in cost-benefit analysis, but Go’s performance is light years ahead of Ruby’s; Go is not good for web apps, but is good for APIs; and Go’s type system is a lot lighter than that of JavaScript’s.

Featured image via Flickr Creative Commons.

Pivotal Labs is owned by Pivotal, a sponsor of The New Stack.