Grant Muller

Ruby, Let’s Take a Break. I Wanna Date Node.js For a While.

Ruby you’re great. No really, I love your terse syntax, iterating is easy, and the community that supports you is quite large. But, I think we need to take a break.

Wait, don’t cry. Let me explain.

It’s just that I’m tired of having to remember so many syntaxes, especially one so different than the others I work with. I have to use C# or Java for my enterprisey stuff, then switch to Javascript for client-side, then switch to whatever templating engine I’m using. It gets…confusing. I caught myself writing a for loop in a file that ended with rb. Seriously.

What’s that? How will I write server-side scripts?

Well, I’ve thought about it and I think Node.js and I are going to start a relationship. Don’t be like that, Ruby. Try to understand. Node is supported on all the platforms I use. I can write scripts in javascript. It’s familiar.

Node and I had our first date last night. I was looking at a Project Euler problem and after working out something that made sense on paper, I glanced over at node and said “Let’s do it”.

We started going at it. Things were looking great at the start but then the night got rocky. My solution on paper just wasn’t working out in code. I wrote and rewrote but just couldn’t make anything work with Node. To be fair Star Trek was playing in the background and my wife was working on her latest project in the same room. The way Spock says “sensors” and the grinding sound of eggshells on sandpaper didn’t really set the mood for solving any problems.

I smiled at node. “I’ll, uh, call you in the morning,” I said, and went to bed.

The next morning I took a long walk with my dogs and thought about what had transpired the night before. Within minutes I had the solution worked out in my head, and I realized it wasn’t node’s fault the night went sour, it was mine. I just needed to sleep on it.

I rushed back to the house, cracked open emacs and tried again with node. It was instant harmony. Here is the brute force solution to problem #3 on Project Euler:

So you see, you’ve been a fun fling Ruby, and we may get together again someday. You know how fickle I am with programming languages. Let’s just take some time off and see where it goes. Node and I may have something here.



  1. I think that some of the extreme hype regarding Node.js as some sort of magic bullet for scalability is unfortunate because it detracts from the other benefits such as the ability to use one language throughout a project and using the same coding style throughout and the great community around the project. With Coffeescript gaining in popularity and improving some of the rougher and annoying parts of JS, I think more people will be looking at Node.js. That being said, picking and choosing the right tech for the job is important and I wouldn’t automatically pick Node.js for a project without considering if its really needed. But its becoming viable pretty quickly.

  2. I know that feel! Did exactly the same thing and honestly: I never regretted it!

    Node, once well understood is a total blast I would never go back. Good job on the text by the way hehe

    1. Actually that’s the beauty of it. Other than the #! interpreter mark at the top, and a few node specific calls to process.argv and process.exit, this is just plain ol’ javascript. From a process standpoint this allows me to write a bunch of simple logic in chrome, firebug or wherever, then when I’m ready move it over to a full-fledged shell script using node.js as my command line intepreter. neat. 

  3. Syntax is the most apparent and least interesting part of any given language.  I don’t think this is in particular a problem that shows much about Javascript; the solution given could be transliterated almost line for line into Ruby, Python, Lua, etc.

    I am not quite sure how to phrase it so that I don’t sound like a jerk because I’m genuinely wondering, but is it really syntax and your solution to Project Euler #3 that make you want to put a language you already know in the toolshed?  Personally, I’m trying to increase the number of languages I use on a daily basis.  The strain you get from switching between languages is like muscle cramps after a hard workout:  as your strength and flexibility increase, they go away.  The broader your working toolset of languages is, the easier it is to come up with a different approach to a problem.  A couple of very different takes on the problem, as an illustration:


    If I had to solve this problem at work, I’d go for the short solution.

    factor $1 | sed ‘s/.* //’

    !/usr/bin/awk -f

    Lest the other one get me accused of cheating.

    BEGIN { p = a = ARGV[1]; for(i = 2; a > 1; i++) { while(!(a%i)) { p = i; a /= i } } print p }

    1. Although I think the act of learning a new syntax and all is a nice workout for your mind, it kind of misses the point. I chose a simple Project Euler problem as a proof-of-concept in writing little shell scripts in javascript, which was probably a bad example, since I intend to use this as a general purpose shell-scripting replacement. 

      I don’t write shell scripts that often. When I do, I would usually turn to ruby. Because I don’t write shell scripts that often, I don’t remember the syntax as well as I might like. If I’ve got ten minutes to write a one-off shell script because I’m on a tight deadline or I’m trying to repair some catastrophe in the real world, I probably don’t want to choose a syntax that requires me to continuously RTFM, wasting valuable time. Since I know javascript, and since node can interpret that for me, it made sense for me to give that a shot and have that in the toolshed for those kinds of scenarios.

      Haskell, Scala, Ruby, Lisp, etc are fun and I like to poke around with them. They’re tools but right now its the difference between a hammer and scratch awl. I can do a helluva lot with the hammer, so I’ll wield it a lot. I don’t get a lot of practice with that scratch awl, so though I might break it out every now and then, I’ll probably focus on bettering my skills with the hammer. 

Leave a Reply