GopherJS nudges Google Go past Dart in JavaScript Web development

With GopherJS, front-end code can be written in Go language, then compiled to JavaScript

Just when we thought Google Dart was Google’s answer to JavaScript, a compiler project is emerging to enable front-end code written in Google Go to run in all browsers.

The GopherJS project, started by developer Richard Musiol in August 2013, compiles Go code to pure JavaScript code, the project’s GitHub page states: "Its main purpose is to write front-end code in Go, which will still run in all browsers." Thus, Go can be used in front-end Web development, Musiol said in email.

"With GopherJS, you can take advantage of Go's elegant type system, compile-time checks, and concurrency model to build client-side applications," said developer Joseph Hager. "By abstracting out the small parts of your project that are specific to either native or Web, you can recompile to JavaScript without changing a single line of code."

Dart and GopherJS are similar in what they intend to accomplish, but Go was designed as a systems programming language, according to Hager. "Dart, on the other hand, was built with the needs and constraints of the Web in mind from the beginning."

GopherJS also supports the Go language's Goroutines concept, getting around JavaScript's restriction on concurrency. "Go's concurrency model takes inspiration from quite a few languages over the past 30 years," Hager says. "Goroutines are the star feature of that model, and GopherJS supports them fully. Keep in mind that JavaScript has no real concept of concurrency, so an instruction can never block. This sort of behavior comes up quite often in Go, and it was an heroic effort on Richard's part to devise a way to make it all work."

Design goals for GopherJS include performance of generated code, similarity between Go and generated JavaScript code for debugging, compatibility with existing JavaScript libraries, and small size of generated code. While the project has no official development status, such as a 1.0 or beta release stage, it could use more developers, says Hager. "If we are going to convince others to give GopherJS a chance, there need to be solid libraries and frameworks they can bet on. There are quite a few intrepid developers trying to make that happen, and I hope we will be able to count you all among them some day."

Copyright © 2014 IDG Communications, Inc.