Refactoring

August 7th, 2010

Since the weekend is upon us and the next few railscasts are a three parter, I’ve decided to combine episodes 10, 11 and 12 into this one blog post. I think that’s fair, don’t you?

Besides, I’m headed to the beach with my family on Sunday. And the ocean with two toddlers means all hands on deck!  It’s all about the kids, people… and the vodka… after they’re asleep in bed.

Ryan says:

Refactoring is improving the design of code without changing its functionality.

In episode 10, we can all agree that moving code from your view into the model is an obvious win.  And I appreciated watching Ryan show us in episode 11 the value of using an array to append a string over a local variable.  Really elegant.

It’s also nice to be reminded of .blank? which will return true if a string is either nil or empty.

But the most important takeaway is using testing to ensure that our zeal to refactor doesn’t break existing code.

Of course, we all test… don’t we?  Riiiiight?

In fact, I believe that the rockstars do.  But the rest of us folks are still doggedly trying to convince our boss of the ROI.

Perhaps your app is so big and so complex that you and/or your colleagues are afraid to refactor.  Well, this is when testing becomes invaluable.

Never tested before?  Don’t let that stop you.  Lord knows I was really intimidated before I wrote my first test.  And I know full well that I still have lots to learn.  But where do you start?

What’s the difference between a unit and functional test?  What about RSpec and Cucumber and all those tools and frameworks that make my head spin?

Let me be the first to virtually take hold of your hand and whisper, “It’s all gonna be okay.”

Just start with Unit Test.  It comes for free with every rails app.  Betcha you got a test directory in your app right now.  Sure, it’s a little neglected but maybe it just needs a little love.

I got a blog post that’ll walk you through the basics.  Chances are you’ve already seen the tutorials though and just need the confidence to get your feet wet.

Just pick a model and write a couple functional tests to start.  Betcha you get hooked.

Entry Filed under: Professional,Railscasts Project,Ruby on Rails

Leave a Comment

Required

Required, hidden

Some HTML allowed:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Trackback this post  |  Subscribe to the comments via RSS Feed


Pages

RSS Tweets

RSS Berkman Gender & Tech

Links

Tags

Meta