Moving

I have moved this blog to GitHub using Octopress, a framework built on top of Jekyll.

The Github/Octopress blog loads in 3.61 seconds compared 10.58 seconds for WordPress. I plan to install the Jekyll asset pipeline to further speed it up.

All the posts that I wrote here have been migrated successfully. For my own reference, this is how to commit to the blog repo:

$rake generate
$git add .
$git commit -am "commit message" 
$git push origin source
$rake deploy

Preparing for a kata

Myles asked me to perform a kata a few weeks ago. After doing some research on sites like codingdojo.org and http://cyber-dojo.com/ (<- cool site, by the way) to find a kata, I decided to perform the Roman Numerals kata. Jordan wrote a good write-up on his experiences with this kata recently.

In the course of doing a screencast doing the kata, I have learned quite a bit. I discovered guard and guard-rspec, which run tests every time the files are saved. By default, guard expects .rb files in the lib/ directory and .spec files in the spec/ directory. When practicing kata, work on the .spec file so you don’t have to switch between different files.

Although my use of vim is improving, I decided not to use it in the kata. Although there are lots of choices, I am using the default Linux text editor. It is easy to use and I can quickly change color schemes (use a high contrast scheme that uses lots of color!). I do miss the vim shortcuts a lot, though.

As for screencasting software, there are a surprising number of options for Linux. I have been using Kazam (unrelated to the movie starring Shaq) although VLC has a feature where a song can be played when recording starts.

I will share the screen capture soon and what I used to help prepare.

Follow-up

As a follow-up to my last post on rebasing, there’s an important step before committing to master from a branch. You should initiate a pull request on master for your newly committed branch so that it can be reviewed before merging. The new branch should run on Travis-ci before being merged. Git doesn’t seem so magical now that I’m beginning to understand how to use it properly.

Rebasing

This past week we started rebasing our Git commits. I was not sure why this was necessary when Myles and Skim suggested this to us during the last IPM but now I do.

Basically, you create a new branch when working on a new feature. You test, develop and push when that feature is ready, then the new code is “replayed” on the existing master branch when you use the rebase command. This is better than using the merge command which can cause conflicts when parts of the code base are changed in both branches.

The main reason behind rebasing is that the master branch should be unblemished and should be a functioning version of the application at all times. This was an interesting process to learn and I recommend reading more about rebasing.

 

Making progress

We have been making progress on our Rails application, implementing Oauth for authentication through Google and completing book check-out and return features. This is is Taka‘s description of what happened. Here is the guide we used. Next up will be to authenticate users with 8thlight.com email addresses. Here’s our site on Heroku – we’ve called it Kihon, which is a Japanese word meaning basics or fundamentals. It is a no-frills app at the moment as we have not done much with the design or UI.

I am getting more comfortable with Rails, although there is still a lot of magic happening behind the scenes. The MVC framework makes more sense now conceptually and that is something I will carry forward, even if I don’t use Rails in the future.

We have been using Github so I am getting better with git too. For testing we have been using Rspec for our formal tests and rails console and pry for our informal tests. Testing is hard but it’s important and necessary.

Myles asked me to perform a kata prior to 8th Light university next Friday so I have been preparing for that. I decided to do the Roman Numerals kata as I hadn’t done it before. I will post more on that soon. I also came across an interesting site called cyber-dojo.com where you can practice katas online.

I finished reading The Clean Coder, a book on professionalism for software engineers. Nathan has written a short review that I agree with. Uncle Bob reasons that you should work 40 hours a week on paid, professional work and spend 20 hours practicing your craft through personal projects, reading/writing, mentoring, meetups, etc. I think it is a good guideline although the time estimates (20 hours!) may be on the higher side. In any case, it provided food for thought and was a good read. It reminded me of Apprenticeship Patterns in the way that Uncle Bob walks us through the journey he has gone through in his career.

I also finished reading a book called How to Live on 24 Hours a Day. I read it based on positive reviews despite being published in 1910. I would describe it as motivational self-help book: practical rather than preachy. It was an interesting read and the author’s advice is much the same as Uncle Bob – including spending 90 minutes a weekday on productive work outside of the office, maximize your time while commuting, prepare for your day before reaching your desk and reflecting on the day’s work afterward. It is out of copyright so you can read it for free as an eBook. I read it on the Google Books app on my phone while on the train.

Back to Basics

Tips for anyone new to software development, especially Ruby and/or Ruby on Rails.

  1. Get comfortable with using the command-line (Terminal)
  2. Learn how to use Vim. Especially if you will be collaborating with experienced developers. It will take you about a week to get used to it but it will improve your productivity.
  3. Figure out the basics of Git and Github. Everyone uses it and you will too

Week in Review

On my first day back at the office, Myles and Steve assigned Taka and I the task of building a web application for the office library using Ruby on Rails. We started with an Iteration Planning Meeting to plan the week’s iteration and the stories (features) we would be working on. This was the first time we had estimated the time frames for our stories (more on that later).

I was excited about having a real project to work but also a bit apprehensive as it had been over since I had done anything in Rails. But we dived in,pairing almost the entire week ,  and made good progress using books like Rails Tutorial, The Rspec Book and Rails Guides. Here’s what I’ve learned over the past week.

  • Estimating stories uses the PERT model – each story has an optimistic, realistic and pessimistic element. The total estimated time is weighted towards the realistic time estimate so it’s best to thoroughly analyze the story considering what you know how to do and what you are doing for the first time (learning along the way). The optimistic and pessimistic elements have significantly less weight but they should be used to maintain a healthy range. Since Taka’s and my estimates are averaged together, our estimates are basically averaged twice. I think this is a positive thing. Our first week’s estimates were on the higher side – we finished most of the stories in less time than we had estimated.
  • Ask the customer specifics before building features. We spent time testing and adding validation for a form that wasn’t specified in our story. While we learned about validation in the process, it wasn’t a good use of our time as the requirements for the form in another story.
  • It’s good to work with a pair. We talk through our problems and our thought processes; this means that our code is analyzed twice on the fly. We maintain a good pace of work as well – I am less tired mentally so I don’t take as many breaks and resume quickly when I do. Since we have been working off Taka’s laptop, I am less distracted and get more work done. More importantly, we compensate for each other’s deficiencies and learn from each other. Our skills are consistently challenged too: I have been learning how to use vim through practice. I would not have willingly done this otherwise.
  • I will try to keep a record of what we accomplished at the end of the day. For whatever reason, I forget what we have done from one day to the next and this is a good remedy.

TDD: What is it good for?

In the course of working on Tic Tac Toe, I wrote tests to place markers (X or O) on the game board.

it “stores X into the 0 position” do
board.store_value(‘0’, ‘X’)
board.data.should == {‘0’=>’X’,’1′ => ”,’2′ => ”,’3′ => ”,’4′ => ”,’5′ => ”,’6′ => ”,’7′ => ”,’8′ => ”}
end

When this test failed, I wrote a store_value method to make the test pass

def store_value(position, marker)
@data = {position => marker}
end

This made the test pass. I wrote another test

it “stores 0 into the 1 position” do
board.store_value(‘1’, ‘O’)
board.data.should == {‘0’=>”,’1’ => ‘O’,’2′ => ”,’3′ => ”,’4′ => ”,’5′ => ”,’6′ => ”,’7′ => ”,’8′ => ”}
end

This test failed and required me to refactor the store_value method because it was overwriting the values in the @data hash. That method now looks like this:

def store_value(position, marker)
@data[position] = marker
end

Now the method saves the marker to its assigned position automatically. This was a simple change but a good one – this would have been more difficult and drawn out if I wasn’t writing tests. Reflecting on my last post, this was what I wanted to improve on and I think TDD will help me get there.

Shifting Gears

I’m now into the third week of my apprenticeship. Last week was challenging – I completed the Coin Changer Kata and moved onto command-line Mastermind. This was a difficult adjustment and I had trouble making progress for most of the week.

I completed reading Apprenticeship Patterns whichwas an insightful, humbling and motivating book. It offered a roadmap for my apprenticeship as well as my career in software development beyond it. At the stage I am currently at, learning Ruby and building basic programs, I found the following patterns relevant:

  • Concrete Skills
  • Confront Your Ignorance
  • Dig Deeper
  • Expand Your Bandwidth
  • Retreat Into Competence
  • Your First Language

Of these, I found that I am firmly into Learning My First Language. After being assigned to create a Mastermind application, I realized my Ruby skills were lacking and studied from RubyKoans and RubyMonk.com [Retreat into Competence].

I was having some trouble with OOP combined with Ruby syntax as I started on my version of Mastermind. I came across Angeleah’s blog post on classes vs. instances of classes which was helpful and moved me along. Although I had a good grasp of the general structure and was generating a code and accepting the player’s guess, I was stuck at comparing the player’s guess with the code.

The general idea is to inform the player if their guess is the correct letter at that position, if it is in the wrong position or if it’s not in the code at all. I was using number codes, so I was manually evaluating the generated code and player’s guess by splitting the numbers into the thousands, hundreds, tens and single digits. Then I was using a function like:

def correct_first_guess
if @first_guess == @first_code
@number_correct << @first_guess
puts “You guessed the first digit correctly!”
elsif @first_guess == @second_code || @first_guess == @third_code || @first_guess == @fourth_code
@number_correct << -@first_guess
puts “You guessed the first digit correctly but in the incorrect position.”
end
@number_correct
end

for every digit in the code. This was tiresome and tedious. Luckily I paired with Myles on Friday afternoon to work on the code. The code to evaluate the player’s guess against the code was simple and efficient, giving a response made of +/-/_

def compare(user_guess, code)
    i = 0
    str = ”
    while i < 4
      if user_guess[i] == code[i]
       str += ‘+’
      elsif code.include?(user_guess[i])
        str += ‘-‘
      else
       str += ‘_’
      end
      i += 1
    end
    str
  end
This is my challenge. I need to change my thought process from doing things manually to automating them. One difference between Myles’ and my approach was that I focused on accepting the player’s guess and worked from there to evaluate it against the code. Myles used TDD to plug in sample codes and guesses, creating responses between them. This was where most of the work was to be done – at the end, we needed to create two very basic methods for accepting the player’s guess and presenting an appropriate response against the generated code. This is not the first time that I have run into this, but now that I have recognized it I hope that I can shift gears and bypass this sort of problem.

Hello world!

First Week Update

I finished my first week as an 8th Light apprentice. I got my feet wet with Ruby by doing the Bowling Game Kata which is meant to correctly score a game of bowling given the number of pins hit on the rolls.

I started programming with nano on the Linux Terminal but I switched over to Geany as my IDE, which coincidentally has a terminal window built-in. I learned about TDD and the “Red, Green, Refactor” paradigm to writing tests and testing with Rspec.

Here’s a code snippet from my Bowling Game Kata.

describe “Bowling Game” do

it “should score 300 for a perfect game” do
game.roll_many(12,10)
game.score.should == 300
end

end

class Game

def roll_many(n, pins)
n.times do
roll(pins)
end
end

def initialize
@rolls = []
end

def roll(pins)
@rolls << pins
end

def score
score = 0
frame = 0
first_roll = 0
while frame < 10
if spare?(first_roll)
score += 10 + @rolls[first_roll+2]
first_roll += 2
elsif strike?(first_roll)
score += 10 + @rolls[first_roll+1] + @rolls[first_roll+2]
first_roll += 1
else
score += @rolls[first_roll] + @rolls[first_roll + 1]
first_roll += 2
end
frame += 1
end
score
end

def spare?(first_roll)
@rolls[first_roll] + @rolls[first_roll+1] == 10
end

def strike?(first_roll)
@rolls[first_roll] == 10
end

end

Despite installing Linux Mint on my Windows PC a year ago, I haven’t had much chance (or reason) to play with it. I have been using it exclusively for the past week and I will continue to use it as my primary development environment. I have been impressed with its ease of use and its reliability.

I started the Coin Changer Kata where the program is supposed to accurately find the correct number and types of coins for a given dollar amount and I will be performing it this week. I was quite sick and jet lagged last week so I hope I can concentrate more on learning this week and make a lot of progress.