May 20, 2008

Posted by John

Tagged thoughts and time

Older: ToDo's On Your Desktop

Newer: RailsConf 2008

Getting Down To The Core Of It

Let me start by saying that today I did something stupid. Ok. That is out of the way, now let’s move on to what I did and how to prevent it in the future.

What I Did

I created a class to parse the hour, minute, and am/pm information out of simple strings (ie: ‘9am’, ‘10:30PM’, ‘12:22 P.M.’). I named it MeridiemTimeParser. Meridiem is the ‘m’ in ‘am’ and ‘pm’ for those that don’t know. I created all the tests and functionality. With the help of a co-worker it took an hour or so and it was all working. Sweet. Seems logical right? I’d imagine you can see a purpose for something like this. The next thought I had was to put it on Github (duh!).

The Problem

As I was doing a git push, a thought came to mind. That thought was, “I wonder if Time#parse would meet all the test cases I need my parser to handle.” My second thought, almost immediately after the first was “Balls, why didn’t I think of that two hours ago.” Being a good little coder, I had all my parsing extracted into their own methods. I edited those methods to use Time#parse instead of the code I had created and re-ran the test case only to discover that I spent a couple hours on functionality built into the ruby core library.

The problem is not that I coded before I thought, though that is a bad habit. The problem is that I am too reliant on Google and too uninformed of the base functionality that Ruby and Rails provide. I’ve seen a lot of people posting about apps that will kill your internet connectivity for a given period of time so that they can focus on coding. Truth is, when I lose my internet, I actually slow down coding because I store so little of it in my brain.

The Solution

This little rewrite of a bit of the Time#parse functionality made it glaringly obvious that I need to know my stuff better. As such, I’m thinking each week or every other week, I’m going to scan through a core library and pick out the goodies that everyone should have in their RAM instead of constantly googling for documentation and blogs.

Everytime I dig into the ruby core libraries or open up rails and browse through stuff I learn a lot. I’m thinking I should force myself to do it and then report on what I learn here. Thoughts? Anyone else think this would be helpful? Maybe I’ll even schedule which libraries for each week and the day I’ll release the post on so people know what’s coming.


  1. After reinventing functionality already in Ruby libraries a few times. I got in the habit of opening up the console (./script/console or irb) and messing around with object.methods.grep(/something/) and console tab-completions as my due-diligence before heavy googeling or cranking out any code that stunk of “I can’t be the first guy to have this problem”.

  2. hey john,

    this has happened to me so many times…
    so i would love to read about your reports.


  3. Hey,

    I found reading “The Ruby Cookbook” just like any normal book, from cover to cover is a very good way to avoid those problems. Frankly I didn’t had the time to do this completely, but the part I read, safed me so many times from writing code that actually shipps with ruby. I think those cookbook books normally are taken out of the book shelf to read on a specific topic that interests one in this particular moment, but their very practically approach makes them worth so much more. Their just covering anything you will need in your day to day work and to say it like John: They don’t bother you with things you’ll never going need, but instead they focus on the things you should keep in RAM :)

    Ok… sorry for the longish comment, but unfortunately my English is to bad to express myself really concise.

  4. As someone who has just recently started a project that involves a lot of pairing, I realize that when I code alone I’m in a sense “pairing” with Google. In some ways pairing with Google is better; the knowledge pool that you can tap into is certainly more vast.

  5. You know, I am of two minds here — it’s very good to know what’s part of the core libraries. Also, it’s good to rewrite something (even if inadvertently) sometimes because that furthers one’s understanding and knowledge. And then comparing your implementation as opposed to the “stock” implementation can be very revealing, too.

    But yes, there is definite utility in going through the library modules.

  6. findchris findchris

    May 21, 2008

    Great idea. I would find it very valuable and illuminating, as I am sure others would.

  7. Hi John,
    I really this idea, where we go through the library first to avoid the “re-inventing” the code thingy. This used to be my approach when i used to do c/c++. This kinda stopped when i came to the rails world. And that i think is the problem with most plp in rails. They don’t focus on the language/scripting lang i.e. ruby and its core lib as much on the overall framework. But I agree with Matt that writing ur own methods does further ur knowledge about the functionality. In fact in college thats what we used to do – implement the “already” implemented core lib methods of C/C++ to improve understand the alogos and logic. This definitely help to be better at programming.

  8. Usefull post! +1

  9. Thanks for all the comments thus far. I’ll try to look through a lib and start this in the next few weeks.

Sorry, comments are closed for this article to ease the burden of pruning spam.


Authored by John Nunemaker (Noo-neh-maker), a web developer and programmer who has fallen deeply in love with Ruby. More about John.


Feed IconRailsTips Articles - An assortment of howto's and thoughts on Ruby and Rails.

Feed IconRails Quick Tips - Ruby and Rails related links.