Problem statement
See the problem statement in this post.
This post is about using the Ruby programming language to write a program that implements a shell (REPL) to JIRA’s servers.
Implement the REPL
I implemented this REPL the same way the C version was made. I opted to not go for the “eval” option (as I did in Tcl) since it allows way too much flexibility for the end-user.
Code
Available here.
This code does as much as the C code does, but in only 60 lines of code. The nicest part is that I didn’t have to use anything more than the standard library to get this done. Ruby is such a nice language.
Thoughts and impressions
Twice the RAM of C
The program used ~25MB of RAM. This is twice that of C and comparable to the TCL program (once you account for external calls to Curl). Just like the other implementations, CPU usage was insignificant.
Amazing programmer productivity
This is a toy program, comparable to work done by programmers fresh out of programming bootcamps. A jira-shell is the CLI version of a frontend programmer making a YouTube clone. And nearly every language looks good when used to make toy programs. But getting all this done in 60 lines of code makes this more a script than a program.
Think about that the next time you click a link to an issue in Jira and twiddle your thumbs for 8 seconds. Try not to compare that experience to a dial-up internet connection from 1995. Seriously, are they running bitcoin mining software in our browsers?
I’ve got about 8 years of professional Ruby experience, so YMMV. I got this code done in 30 minutes. 10 minutes of that was looking up the API of Net::HTTP. I swear, the net/http api is the only beef I have with the Ruby standard library.
I get in flow
Tbh, I got into flow and the script was done 2 minutes later; it’s that short a program in Ruby. A combination of “dig” and “.each” makes parsing arrays and hashes (and thus, JSON) stupidly simple. What a waste of perfectly good flow.
Holy moley Forth!
One thing I noticed about Ruby that I hadn’t noticed before reading about Forth was how much opportunity it provides for building fluent interfaces via method chaining.
This is a pattern I first came across in Clojure where they are called threading macros (-> and ->>). Elixir has similar functionality but they call it a pipe (|>), with the syntax being a combination of the pipe (|) and redirect (>) operators in POSIX-shell.
Method-chaining has been derided since it breaks the law of Demeter. But in the grand scheme of things, calling methods on objects and calling functions with objects as arguments isn’t that different. Algorithmic flow remains the same. And all the hipster programmers love Clojure’s threading macros and Elixir’s function-pipe. Even if they didn’t, I love Unix pipes, and I’m not giving them up. I just never groked, till now, that they look and feel like a special-case of stack-based programming.
Leave a Reply