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.

SB apprenticeship: Day 18

Luckily, someone warned me that this was alcoholic before I drank a big delicious glass and went to meet my boyfriend's parents for the first time drunk. *whew!*

Luckily, someone warned me that this was alcoholic before I drank a big delicious glass and went to meet my boyfriend’s parents for the first time drunk. *whew!*

I’m still getting used to this whole ability to drink (responsibly!) at work thing. Last week we had cider, and as I settled in to listen to people present their labs projects I kept expecting someone to take me aside and gravely tell me that the taps are just for show, and drinking at work is wrong, and they’ll have to let me go now. This is a different work environment than any I’ve ever had, and it’s really great. Yesterday one of the women messaged me on Slack and was like, “Hey, I think we should be friends. Let’s do that.” I’m not sure if it’s just kind of inherent to tech/startups, or because everyone’s relatively young, or if they select carefully for personality, but it’s awesome, and every day I’m glad to come in to the office.

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

I’ve been trying to organize my day into bite-size chunks, so I spend ~an hour on my kata, ~2 hours reading, ~2 hours on online tutorials and ~2-3 hours on the assignments. That ensures that I’m working on all the various parts I’m supposed to get done during the apprenticeship, gives me some structure and also gives me a stopping point when I’m frustrated. Yesterday it worked fairly well, but I still mostly feel like I’m hacking my way through the jungle with a butter knife.

Brandon just told me that today we’re going to pair on the Roman Numeral kata as a way to teach me Vim. Eep! I think I’ve build Vim up into this hugely intimidating thing that it isn’t actually. I’m looking forward to learning it better. One of my friends had a great way of putting it:

“I feel like learning how to use vi is like learning how to play chess. You could learn the basic “rules of the game” in an afternoon, or you could devote a lifetime of practice to becoming a grandmaster. Most people never go very far beyond the rudimentary level, with minimal costs to overall quality of life.”

Today I expect to learn Vim! Well, the rudiments of Vim, at least. I’m also going to try really hard to stick to my schedule and hit everything on my itinerary at least once.

SB apprenticeship: Day 11

Real programmers set the universal constants at the start such that the universe evolves to contain the disk with the data they want.

One of the interesting things about learning how to program is how much some of the other things I’m into make sense now. For instance, I’ve been reading XKCD for years, but honestly only understanding about a third to a half of them. The jokes about math or programming mostly went over my head, unless they were visual gags like the ‘compiling‘ one. When the comic above came out, in 2008, I not only had no idea what vim, emacs, ed or cat were, I didn’t even know what they were referencing. There’s nothing in that comic to explain what an editor is, or an IDE, or what the difference was, or why they were important. Which, of course, makes sense, Randall Munroe is a programmer and this is a comic for that audience. Also, to quote E.B. White, “Explaining a joke is like dissecting a frog. You understand it better, but the frog dies in the process.” But since I started learning to program, people will link to old comics and I find myself appreciating the humor in an entirely different way, and that is super cool.

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

Yesterday I worked on the Roman Numeral kata for the second time, and actually finished it! The first time I got super frustrated because nothing I was trying was making sense, so Brandon suggested that I work on Coin Changer some more. In one of her blog posts, Lindsey posted a link to a woman who worked through the kata in a way that really made sense to me, so I used that as a reference and managed to complete it. I was feeling pretty good about that, so I worked on adding tests to my 4×4 tic tac toe with Jordan for a bit, and then decided to tackle the next challenge: learning how to SSH into a server and post some static content. That…was a little less successful. The page describing the assignment was out of date, so I ended up needing Josh to sit with me for a bit and walk me though the terminal commands to get started, and just as I was nearing the end I discovered that using nginx to serve up an HTML file on a server required me to know Vim. Viiiiiiim….so daunting. (But see, that comic at the top was totally relevant!) Vim is an editor that I’ve heard is super awesome. Once you get the hang of it, it’s all keyboard commands to do what you want. It’s powerful and widely used…and has a learning curve roughly the size of Mt. Everest. The cheat sheet I found and printed out is seven pages long. Sigh. Still, I’ve known this day would come, and honestly I’m looking forward to learning Vim. I’m just a little nervous, is all.

Today I’m going to work on the SSH stuff. I’m not sure how much Vim I’ll actually need to know to get through it, but I have my cheat sheet in hand and am feeling ambitious. Also, yesterday I rewrote the documentation for the assignment and did a pull request for it. Ian is taking a look at it now, so if I need to make any corrections or add anything before it goes live I’ll do that.

I expect to learn enough Vim to be able to put a static HTML page on a server using SSH. Exciting!