Cymen's Blog

Archive for the ‘8th Light’ Category

Day 16: New project — HTTP server in Clojure

leave a comment

My next project is an HTTP server in clojure. I can use sockets. A quick search revealed clojure-contrib that has server-socket. The project needs to pass the cob_spec web server test suite from 8th Light. The test suite is built on top of FitNesse which is another project from 8th Light: a sort of mashup of wiki, requirements and testing.

While mulling this over I’m continuing to work on the Clojure Koans and attempting to do a Kata. I asked Doug and he said it’s normal to feel really weird trying to do a Kata but you basically just need to do it just like brushing your teeth.

Written by Cymen

February 22nd, 2012 at 11:54 am

Posted in 8th Light,Apprentice

Day 15: Starting the Clojure Koans

leave a comment

I finished the HTTP version of my tic-tac-toe ruby game in about two days instead of 1.5 weeks so I was out of things to do. In the morning I spent some time looking at how ASP.NET MVC compares to Ruby on Rails and spent some time moping about katas. I just don’t get them to be honest. I’m guessing you have to “taste” them to get them but I have a hard time getting started. It may be that I don’t like the idea of performing code in public. It may also be that so far I’ve gotten nothing out of attempting to observe katas at 8LU due to the projector resolution, contrast and sitting distance. I’ve tried to move closer but then the kata was in clojure which I wasn’t familiar with so it was going too fast… I’ll need to bite the bullet and just start doing a kata at the start and end of every day.

I started the Clojure Koans in the afternoon. I’m using leiningen which was very quick to get setup on Ubuntu 11.10. So far, I like it… The initial reaction is that the syntax is a bit terse and it’s harder to break it into chunks but time with the REPL is helping.

I forgot my wallet at home but thankfully I also forgot half of my lunch so that worked out. Speaking of lunch there is another rant there. The 8th Light tradition is for everyone to eat lunch together every day. I like it but not every single day. Of course it is only for the duration of the apprenticeship but being limited this much at lunch time really cuts lunch options, the occasional socializing with people outside of 8th Light, and taking a bit of mental time to oneself. Maybe it’s okay to break the lunch rule every once in a rare while? It is important to note that overall the office experience is very nice and this is a minor complaint.

Written by Cymen

February 21st, 2012 at 4:39 pm

Posted in 8th Light,Apprentice

Day 14: Reviewed HTTP-based tic-tac-toe with Doug

leave a comment

Doug reviewed my tic-tac-toe project to see the progress I’d made on the HTTP implementation. We discussed some of the aspects of testing that were difficult. He is going to return with the next challenge but in the mean time I’ll work on making sure my HTTP-based tic-tac-toe using Sinatra is completely tested. I split my state interactions off to a TicTacToeStorageSession class which made testing easier as I could inject the session as a hash instead of a Rack session (the Ruby hash has the same interface as the session for my purposes).

I added more testing of to the project. Testing the “actions” in my Sinatra-based tic-tac-toe application was straight forward and thankfully there are few of them. I also added more testing to other parts of the application where prior refactoring exposed methods to use to set values for testing of functions that use those values (typically, along with other input).

Written by Cymen

February 20th, 2012 at 12:01 pm

Posted in 8th Light,Apprentice

Day 13: Working HTTP-based tic-tac-toe

leave a comment

I worked on my HTTP-based tic-tac-toe project. I can now play the game on the console with:

ruby play_console.rb

Or via HTTP (using Sinatra) with:

ruby play_http.rb

I am still figuring out how to do testing with Sinatra. It looks fairly straight forward but the part I remain unclear about is redirects. So I’m looking into that next. The game uses POST when the human/HTTP player makes a move but uses a GET when choosing if the human/HTTP player would like to be X or O. That should probably be a POST but doing a nice clean prompt for X or O and submitting the result with a POST is not as clean as I’d like. Maybe another attempt or two will result in something that is cleaner.

For more details, see the TicTacToeHttp class

Written by Cymen

February 18th, 2012 at 4:12 pm

Posted in 8th Light,Apprentice

Day 12: HTTP-based tic-tac-toe

leave a comment

I spent some time reading about Sinatra today and yesterday in order to put an HTTP interface on my Ruby-based tic-tac-toe game. By early afternoon, I had a board that was fetched via HTTP with a URL to GET to play a space. I hooked up an instance of the ComputerPlayer class (which uses a Negamax solver) and had the player on the HTTP side always be first (so X in tic-tac-toe). I used Rack::Session::Pool so that I could keep the game state on the server side (instead of the default session which would put it in a cookie). I saved the Board object into a session variable by using Marshal.dump() on it to serialize it to a string.

This worked out well! However it is untested and the Scorer hasn’t been hooked up yet nor the prompt to choose if human/HTTP player wants to be X or O. So those are the next steps…

Written by Cymen

February 16th, 2012 at 3:47 pm

Posted in 8th Light,Apprentice

Day 11: Review of tic-tac-toe and the next thing

leave a comment

Doug reviewed my console-based tic-tac-toe solution in ruby. We discussed some of the areas that I had problems testing and some ruby patterns that could make some of my work more elegant. The next challenge is to make the project work with both a console and HTTP interface.

Written by Cymen

February 16th, 2012 at 3:41 pm

Posted in 8th Light,Apprentice

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

leave a comment

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.

Written by Cymen

February 14th, 2012 at 7:58 pm

Posted in 8th Light,Apprentice

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

leave a comment

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.

Written by Cymen

February 13th, 2012 at 2:46 pm

Posted in 8th Light,Apprentice

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

leave a comment

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).

Written by Cymen

February 13th, 2012 at 11:06 am

Posted in 8th Light,Apprentice

Day 7: Testing approach pays off

leave a comment

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.

Written by Cymen

February 9th, 2012 at 3:25 pm

Posted in 8th Light,Apprentice