Cymen Vig

Software Craftsman

Day 10: Getting tic-tac-toe ready for demo

I spent the day cranking away on my tic-tac-toe project. I am still a little uncomfortable with the approach to unit testing the input-output. In short, the test is counting how many times certain functions are called. It did indeed catch at least one bug however this means if I want to test IO I need to occasionally make an additional function or method purely in order to count how many times it is called for testing. I’m mostly convinced just slightly unsettled by that requirement.

The other issue I have with the approach is that for every single method we have an additional variable to count how many times it was called. That gets messy as the number of functions or methods increases. Maybe that is a sign that too much is being done by that module or class? I was thinking one solution to this would be to add something that gets called when any method or function is called and it increments a hash value with the key being the method or function name. I think this is possible in ruby… I can immediately think of at least one downside but it might be worth trying.

At the end of the day, my tic-tac-toe is almost completely tested. I’m finishing up testing a module that does output for the board printing and line centering on the console. Then another round of making sure I didn’t miss testing a function or method.

Comments and Reactions

Day 9: On site at a client, more work on tic-tac-toe

I met Doug this morning at an 8th Light client site. I observed the SCRUM stand up of the team working with Doug and some subsequent meetings. It was interesting to hear some of the philosophical approaches that 8th Light encourages. I believe some of them were discussed by Uncle Bob on the 8th Light blog titled Clean Architecture.

Doug and I went over my tic-tac-toe progress and he pointed me to a post by Josh on cleanly testing input/output in Ruby on the 8th Light blog: Testing Code That’s hard to test. I am reading that and will then work on fancying up and cleanly implementing the console portion of my tic-tac-toe game. It is going to be tricky not to violate the single responsibility principle.

Comments and Reactions

Day 8: 8LU, some Backbone.js and more Negamax

I forgot to write my blog post for day 8 so I’m writing it on day 9. Day 8 was a Friday at 8th Light which means we host 8th Light University also known as 8LU. Part of the responsibilities for apprentices is to help clean the office and help with 8LU. That took up a fair amount of the morning as I also setup a Waza board as directed by Doug. The Waza board is for listing the open source projects being worked on after 8LU by anyone (typically an 8th Light employee but it can be someone who happened to stop by for 8LU as it is open to everyone). The board has a column for each project and the rows are name, team, ready (stories), working (stories) and done (stories). This seemed to be popular as Paul/Doug wanted to streamline the stand up and move the Waza related content out of the main stand up to make it faster.

For Waza, I worked with Mike on Backbone.js. He is giving a presentation on Backbone.js to the Software Craftsmanship McHenry County (link goes to meetup details for 2/15/2012). Apparently, that meetup location doesn’t have a good internet connection so he wanted to modify his Todo list example to use HTML5 local storage. He had an existing project in rails which relied on something on the rails side for some template formatting so we needed to abstract that. We had a hard time doing that quickly and settled on temporarily hard coding the few templates to JavaScript functions. This got us to the point we could try the local storage plugin for Backbone.js and it turned out to be super easy – a minor change to how we were using collections in the page and adding a single line to the initialization of the collection and it worked! We committed and ended our work at that point. I believe Mike is going to look into the issue with the templates.

In the evening and on Saturday I worked on my Nega implementation for the tic-tac-toe project in Ruby. I’ve posted that project here on github:

https://github.com/cymen/ttt-ruby

By the end of Saturday, I had a working Negamax that passed all my test cases. I then quickly hacked a play method into my Game class and added a play.rb that loaded up the classes/modules and kicked off play so I could try the game on the command line. Next is to cleanly implement the console display and input in a tested way and look for violations of the Single Responsibility Principle (SRP).

Comments and Reactions

Day 7: Testing approach pays off

I spent the morning bashing my head against Negamax trying to figure out why my approach wasn’t working. In the afternoon, I decided to go forward from what I knew was working with my test cases so far instead of trying to make a huge leap (my huge leap was running it on an empty board which was returning 0 for all spaces).

The pay off was that I was able to resolve a sign bug in my implementation by writing another “small step” test and then fixing the bug that prevented it from working.

Comments and Reactions

Day 6: Minimax to Negamax

I have a working version of minimax/negamax. On an empty tic-tac-toe board, it will return 0 for each square. This makes sense because it is basically playing itself so every choice is going to result in a draw. Only while talking to Wiley (another apprentice) did that become clear. That means there needs to be some more initial logic somewhere for the computer to pick the initial space at the beginning of the game if it is x as some spaces are better than others for optimal moves. Or the depth of the move could be a multiplier of the returned value so that good “more close” moves down the tree are weighted heavier than good moves further down the tree. Hrm…

Comments and Reactions

Day 5: Minimax

Today I attacked minimax and slowly figured out how to use it. I’m almost there – I’m able to iterate over all the possible tic-tac-toe boards but I’m not weighting the moves appropriately in the case of blocking the opponent. The wikipedia article is pretty clear though so hopefully I can finish it this evening after a break.

Comments and Reactions

Day 4: Progress on Tic-Tac-Toe in Ruby using Test-Driven Development

After figuring out rspec I created classes for the board, scorer, and selector. I initially started on the minimax implementation after the scorer however in talking with Ben (add link) it was clear the single responsibility principle would be violated without separating out the code for selecting the horizontal, vertical and diagonal rows from the board.

Ben and I talked a little bit about the implementation details on how the spaces are stored. It sounds like most people are using an array and converting the 0-8 indexed array to 1-9 labels on the front-end. I mulled over my options and went with a hash with the keys 1-9. Still not 100% certain it’s the right path but I’d rather not deal with off by one errors (even with testing one still has to write additional code – even more to test that off by ones aren’t happening).

I was happy to see how quick it was to refactor the scorer class into a scorer class and a selector class. The first iteration was taking everything relevant to selection over to the selector class and adding or bringing over tests without changing the scorer class. Now that those tests are passing, I can go on and refactor the scorer class to use the selector class.

Comments and Reactions

Day three at 8th Light

I completed the koans yesterday however I wasn’t happy with a few solutions. I reviewed one of these with Doug and we tried to come up with a cleaner solution however it didn’t really seem possible. Or at least nothing cleaner came from either of our minds. This is normally where I move on and let the subconscious take a crack at it.

The next assignment is to work on a ruby implementation of tic tac toe that is:

  • fully tested

  • uses classes that follow the single responsibility principle (SRP)

  • can be played on the console

  • can choose who goes first (computer or human)

  • uses MiniMax algorithm for the computer player

Comments and Reactions

Second day at 8th Light

Today I’m a bit off! I got in a bit later than planned and fumbled the morning greeting. I think everyone is supposed to say hi to each other. I like that. But I felt shy and wasn’t sure if I should interrupt and say hi. Tomorrow I’ll get it right!

I’m continuing to work on the ruby koans. Right now, I’m at 159/280 after just finishing figuring out how to raise the exceptions in triangle.rb when the triangle lengths are invalid. I ended up going to the stackoverflow link mentioned in about_triangle_project_2.rb. This is going a bit slower than I expected however I definitely see the value as I’ll be coming back to this when I hit the corner cases in ruby and can’t remember the correct behavior.

Comments and Reactions

First day at 8th Light

I started as a resident today at 8th Light under Doug Bradbury. The day started with some quick paperwork, siting in on a weekly project meeting and then starting to work on these ruby koans. Doug brought me a sub from a local indie sub shop (can’t remember the name off hand but I’ll be back update: JP Graziano) and then I continued in the afternoon with the ruby koans. We also went over the reading list: continue the overview parts of Agile Software Development while skipping the case studies unless interested and start with Clean Code.

It turns out we have a slight fruit fly problem in the downtown office. As we have one at home too I went out and brought some apple cider vinegar and some cups and have placed them around the office. The trick I’m using at home is to put a tiny bit of dish soap in to act as a surfactant. A surfactant lowers the surface tension of a liquid which means the fruit flies can’t “walk on water” so to speak and will fall in and drown when they attempt to drink the vinegar. The sharp smell may also attract them.

Comments and Reactions

Reading List for 8th Light Fellowship

I’ve created a list at Amazon.com for the books to be used during my fellowship at 8th light: 8th Light - Book List.

Comments and Reactions

Transition: Webitects to 8th Light

I’m starting an 8th Light fellowship with Doug Bradbury on February 1st, 2012! I am very excited to learn more about test driven development, software design and agile methodology by practice as an apprentice.

I am going to miss the team at Webitects. For the past two years, I’ve worked on a number of interesting and challenging projects. It has been a really good experience and I will definitely stay in touch.

Comments and Reactions