Go and AngularJS

Last week we launched Daily Reporting for ebook sales at my employer Smashwords. It's built on angularjs-nvd3-directives, which are obviously AngularJS directives built on top of nvd3, on top of d3. On the backend we're supplying the data via a Go server with go-json-rest, and Gorilla web toolkit.

I blogged last September about AngularJS, but I'm sad to say that my excitement about AngularJS has waned significantly since then.

The biggest strength and weakness of AngularJS is that it is forcing Javascript to be something that it really isnt: organized. This is its strength because code needs to be organized to be testable and comprehensible. The bigger your code base gets, the more you need reusable well-structured components. If you've done much straight Javascript, you've probably seen some Javascript code bases spiralling out of control, devolving into giant masses of moldering garbage. AngularJS won't allow you to write that.

This structure is also AngularJS's weakness, because it means the framework has to go through a lot of insane contortions to build that structure on top of Javascript. This means that AngularJS is complex, and that to the end developer, much of what happens appears to be magic. As a developer who works all over the code-base from front-end to back-end and everything in between, tools that have a huge amount of complicated parts to remember and interact with are not ideal. It also means that code written in AngularJS is often impenetrable by developers unfamiliar with AngularJS, which is definitely not ideal if you want to keep your team bus factor low.

I'm not saying that AngularJS is bad, persay, or that you shouldn't use it. I also think that it is likely that a lot of the complication that AngularJS had to build to make the framework run will melt away into the next version of HTML and ECMAScript. This is an ideal solution to the problem. In the meantime though, I'd advise against throwing caution to the wind when you introduce AngularJS to your projects.

On the other side of the spectrum entirely is where we'll find Go. When I first started writing Go, I really wasn't that excited about it. Isn't Python enough? Doesn't everyone love Ruby? C# is great with Mono. No exceptions? What do we really need another language for?

Go is simple.

Go source code is readable, and auditable, and it takes the whole "composition over inheritance" to its most extreme conclusion by not even allowing inheritance as you know it. Go has no operator overloading, no method overloading, no subclassing, no exceptions, and, really, no classes.

Instead it offers structs, method receivers, automatically-satisfied interfaces, embedded fields, and multiple return values. These features serve to provide a very different way of writing object-oriented programs than other popular languages these days.

Go isn't going to strike you as sexy.

Its syntax is C-like, without semicolons in the same manner as Javascript via automatic semicolon insertion. When you write Go, you're going to write a lot of error-checking code, because the error is passed back as a parameter to the calling method, and ignoring it with a "_" is liable to get you mocked by the community. On the other hand, if handling errors really bothers you, maybe you shouldn't be making your code available to the community anyway?

The age-old debates about static versus dynamic languages aside, Go's competitors are really very different. If you don't want to write in C or C++, and want something compiled, Go is an excellent choice. And as many developers have exclaimed, Go is fast and performant.

Last week at the Linux User Group of Davis, I did an "Intro to Golang":

Go has crept into my little programmer heart line by line, in complete contrast to AngularJS. AngularJS promised a lot of improvement over your typical Javascript stack, and delivers on that, but with a huge amount of added complexity. Go promises very little over your typical backend stack, but by its very design, aids you in writing better and simpler code.

That's something I can definitely get behind.

Obligatory note: Does this sound like the kind of programming you want to do? Do you love ebooks? Contact me at firstlast @ gmail.com.

Syndicate content