Archive

Archive for April, 2009

MasterMind Kata in Ioke

April 28th, 2009 3 comments

Ioke is a new language that I’ve been wanting to learn for a few weeks. I like the vision statement for this language: “Make it as expressive as possible. Period“. Ola Bini, its author, doesn’t want to focus on performances early because it would break expressiveness. Take a look a primitives types versus plain Objects in Java to understand why.

However I had no idea of what interesting code to use it on. Difficult to learn a programming language when you don’t know what to program.

So, as I try to go to the Coding Dojo every Monday, I felt that Ioke could be used to prepare the MasterMind Kata (link in French).

Here is the code, reworked after the Dojo to make it clearer:

countCorrectColorAndPosition = method(secret, guess,
  secret zip(guess) count(equals?)
)

countCorrectColorWrongPosition = method(secret, guess,
  pairsWithWrongPosition = secret zip(guess) filter(different?)

  secret distinct map(color,
    countWrongPositionForOneColor(pairsWithWrongPosition, color)) sum
)

countWrongPositionForOneColor = method(pairsWithWrongPosition, color,
  [pairsWithWrongPosition count(first == color),
    pairsWithWrongPosition count(second == color)] min
)
Mixins Enumerable sum = method(self inject(+))
Mixins Enumerable distinct = method(set(*self))
Mixins Enumerable equals? = method(self inject(==))
Mixins Enumerable different? = method(self inject(!=))
use("ispec")

describe("countCorrectColorAndPosition",
  it("should recognize when no peg is correct position or color",
    countCorrectColorAndPosition(["B","B","B","B"],
        ["N","N","N","N"]) should == 0
  )
  it("should recognize when one peg is correct position and color",
    countCorrectColorAndPosition(["B","B","B","B"],
        ["B","N","N","N"]) should == 1
  )
  it("should recognize when all pegs are correct positions and colors",
    countCorrectColorAndPosition(["B","B","B","B"],
        ["B","B","B","B"]) should == 4
  )
)

describe("countCorrectColorWrongPosition",
  it("should recognize when no peg is correct color",
    countCorrectColorWrongPosition(["B","B","B","B"],
        ["N","N","N","N"]) should == 0
  )
  it("should recognize when a peg is correct color and wrong position",
    countCorrectColorWrongPosition(["V","B","B","B"],
        ["N","V","N","N"]) should == 1
  )
  it("should recognize when there are more pegs of a given color in the guess than in the secret, and ignore these pegs",
    countCorrectColorWrongPosition(["V","B","B","B"],
        ["N","V","V","N"]) should == 1
  )
  it("should ignore pegs with correct position and color",
    countCorrectColorWrongPosition(["V","B","B","V"],
        ["V","V","N","N"]) should == 1
  )
  it("should recognize when pegs are correct colors for multiple colors",
    countCorrectColorWrongPosition(["V","R","B","B"],
        ["R","V","N","N"]) should == 2
  )
)

(For a better reading).

First part is the code itself.
Second part, I had to write a few Mixins that could be included in standard Ioke library (remember it’s a very young language)
Last part are the unit tests, BDD style. I’m more used to TDD so forgive me if it’s not pure BDD.

Hope this will make you either want to practice Ioke or come to the Dojo.

Java libraries and frameworks supported by Google App Engine

April 12th, 2009 4 comments

I’ve just posted a Google Spreadsheet to list java frameworks and libraries supported by Google App Engine : http://spreadsheets.google.com/pub?key=pRJ_0hajVrhacLjp3HqD5ew

appengine_lowres

Feel free to update and share.

Google Moderator on Coding Style Preferences

April 10th, 2009 Comments off

I’ve just started a Google Moderator on Coding styles. The idea is to find which coding style preferences are accepted by the majority, which interest nobody and which are balanced between likers and haters.
Google Moderator is not the perfect platform for this kind of experiment (no code formatting, no urls…) but I wanted to give it a try.

Feel free to add a lot more questions.

JavaCampParis 4th edition

April 1st, 2009 1 comment

Yesterday was the 4th edition of JavaCampParis. It was a great event in a great place (Google’s offices in Paris). I must say that after a very boring Scrum User Group, this was a real change. Read more…

Tags: ,