Friday, March 22, 2013

blast from the past

Yesterday, when I wrote the last line of that code snippet, I felt weird. It didn't feel right.

Today, when my friend and mentor The Fridge read the post and saw it, he said that last line was practical, but could be a bad idea in Rails views, because it could bloat the code in no time.

Thinking about it reminded me of the pairing session I had with one of Thoughtworks guys. Then I decided to revisit the code we wrote on that day. I've discovered some really cool stuff:

  • The true magic of git: I was running my code on an Ubuntu VM at the time. After I was lured to the dark side of the Force I deleted the VM and saved all my Ruby stuff in a tar.gz file. After more than an year, I extracted it all to a folder in Windows, and EVERYTHING was there: the repo was working, all the commit history, even the files' statuses was untouched. It was really mind blowing. Would it happen if I was using SVN? I don't think so. I guess Linus is right.

  • All my tests were green: yay!

  • My code was broken: damn! That boot camp was one of my first experiences with TDD, so that's ok, I guess. I had all my classes and methods covered by tests, but my main source file wasn't. Or maybe I had tampered with the code recklessly after the boot camp, I don't know. But the cool thing was: I had and old piece of code that wasn't working. Then I wrote a new test for and old broken feature. And I was like "I wonder if that's how it feels like to deal with legacy code using TDD". I haven't got to that part on Kent's book yet, and I know there are some good books on this topic.

  • Yep, that code was bad. I remember Netto telling me that stuff like that exposes the guts of your class and that's bad. (his wording was better, for sure)

So a better way of doing it would be something like this:

Ah... That's much better... =)

2 comments: