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!).
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.
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.