Recently I set out on an interesting journey. I wanted to build programming
libraries for my API, HolidayAPI. Some of the languages I know like the
back of my hand. Others, have never even touched them before.
Before you start sending me hate comment, I am fully aware of
Swagger. I had given it an honest shot but I felt the resulting code
was bloated. The resulting libraries had a bunch of files and I was able to fit
each library into a single file that was less than 100 lines of code. In fact,
the largest library was only 62 lines of code.
Bloat aside, I was fearful that taking such an approach would leave me
attempting to maintain code that I didn’t fully understand. I most likely would
have figured things out but I figured that writing each library myself would
make maintenance easier.
So I set out to write a library in five different langauges. I started with what
I am the most fluent in, Node.js and PHP. Then I attacked Ruby and Python, which
I have a small bit of working knowledge. Rounding out the pack was Go.
Go (or is it Golang?) ended up being the most challenging. The only experience I
have with Go was working through a tutorial years and years ago. I had never
built anything worth the shit with it.
It took a few weeks of casual evening hacking but all 5 libraries are available
for immediate consumption. Here’s what I had learned about each of the languages
I had worked with during the process:
Versioning code is pretty much perfect in Node.js
When I say versioning, I am referring to something like an API that has multiple
versions and verbs / endpoints available. Since you can nest objects in
JavaScript, the resulting library had very clean interfacing:
HolidayAPI.v1.holidays(params);
I still dig that PHP doesn’t make you explicitly require core functionality
Ok, ok, ok… we get it. PHP sucks, yadda yadda. Thing is though, every other
language that I worked with required me to explicitly require different bits of
core functionality. There’s probably an argument in there that this speeds
things up or whatever, but for developing in languages that I am not entirely
fluent in, it makes things easier.
PHP also gets props for being able to combine namespacing with classes and
functions to achieve a similar level of awesome in regard to versioning the
interface out cleanly.
I still don’t feel the Ruby syntax is human readable
I remember the argument early on that Ruby makes sense because it’s has very
human readable syntax. I’m sure if I spent more time with it, it would click for
me but as a casual, I still found somethings to be confusing compared to other
languages that I have worked with.
Python really is a gorgeous language
It had been a while since I wrote something from the ground up with Python. The
resulting code ended up being the smallest and most elegant of the batch.
Can’t tell if I love Go or if I want to punch it in the face
So the jury is still out. Go was the language I had the least experience with
and thus, had the most difficulty writing in. My ineptitude is not the
language’s fault, but the documentation I found online left a lot to be desired
for me.
Even though it’s a very strict language, I was able to coax Go into letting me
work with data that was similar to an object in JavaScript. For anybody looking
for the same, try map[string]interface{}
.