SB apprenticeship: Day 19

Seriously, what is this?

Seriously, what is this?

I am ok at building new projects from scratch. I’m not good, but we did a lot of that in code school, so I at least know where to start, and where to look for help, for the most part. But man, legacy code…what even is that. This quarter of the apprenticeship is focusing on refactoring, and one of the katas we have is the Gilded Rose. For this kata, we take a whole bunch of ugly code that is a method to update the inventory of a store based on the number of days the item has to sell by, and the quality of the item, which either increases or degrades daily.

I opened this file and literally said, “Whaaaaaaaaat…” It’s just a single method, with tons of nested if statements. I tried to read through it and still didn’t really understand what was going on, I ran the test suite, which didn’t help, I asked Brandon, but he’s super busy this week and hasn’t had the time to go back and refamiliarize himself with it. I even asked Kevin, who had basically the same reaction.

So…like, how does this refactoring work? Am I supposed to go through and rewrite the entire thing, making more methods for each category of item? Brandon mentioned that I had to add like seven lines of code, but I can’t even see where to add code to this. I looked online, and the solutions, like the link up there, are exactly the same as the code I have, so either I’m missing something big or they’re not actually posting their solutions? Sigh. This is what I’m going to tackle today. I don’t actually want anyone to tell me the solution, I just wanted to complain a bit.

  • What did you learn yesterday?
  • What are you going to do today?
  • What do you expect to learn?

Yesterday was pretty much entirely spent learning Vim. Brandon came and installed Macvim (with a whole bunch of plugins) and iTerm because I apparently need a terminal emulator? I spent the afternoon doing the first three levels of VimAdventures, which is super cute but requires you to pay to play past that, and the VimTutor that comes with the editor. I also found a whole bunch of videos covering the basics, and Brandon suggested that I check out Vimcasts.org.  I will admit that using Vim, even as slowly and clumsily as I currently am, makes me feel like a l33t hax0r, which is pretty cool. I have an unironic love for the old 90s movie Hackers; last night I told Mason, my Ruby instructor from TIY that I was going to take up rollerblading and hack the Gibson next. 

Today I am going to work on Gilded Rose some more. The apprentice who was right ahead of us did that assignment, so I think I might pester him to get a hint of how to begin. If I get frustrated I’ll learn some more Vim.

I expect to learn some more ways of dealing with terrible legacy code! I know this code is deliberately bad, and with any luck I won’t have to work with anything quite so bad in my actual career, and that helps.

Advertisements

One thought on “SB apprenticeship: Day 19

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s