суббота, 3 декабря 2011 г.

Coderetreat in Lugano

On Saturday, December 3, the first Coderetreat took place in Lugano. It was leaded by Hamlet D'Arcy and hosted by Ex Machina. JetBrains was among the global sponsors of the event (thanks to it I increased the number of my T-shirts by one).

Coderetreat is a world-wide event where software developers exercise in writing code. In particular, this Coderetreat was organized in six 1-hour sessions (45 mins for coding, 5 mins for discussion and 10 mins for a break) + 1-hour free lunch. In each session the rules were the following.
  • Developers implement the same task (which was the Conway's Game of Life, described below).
  • The work is done by groups of two people. The groups change each session.
  • In the end of each session all the code is deleted.

The Conway's Game of Life is a self-developing world of cells that can be either alive or dead. The rules of the world are the following.
  1. Any live cell with fewer than two live neighbors dies, as if caused by under-population.
  2. Any live cell with two or three live neighbors lives on to the next generation.
  3. Any live cell with more than three live neighbors dies, as if by overcrowding.
  4. 4. Any dead cell with exactly three live neighbors becomes a live cell, as if by reproduction.
Note that the world can be infinite and/or closed from any side (i.e. a cell going to the left arrives from the right). Also the cells, theoretically, may be of any geometrical shape.

The whole idea of the event is that every session a set of suggestions is given encouraging developers to explore different approaches to the task implementation. In particular, the following suggestions were given session by session.

1. Developers got familiar with the task and started designing and implementing the solution without any restrictions.

2. As a result of the previous session, most of the groups had the concepts of a Board/Grid and a Cell that had a boolean state isAlive. First, it was proposed to get rid of the primitive types like boolean and replace them with abstractions. For example, the class Cell may have subclasses AliveCell and DeadCell. Another suggestion was to use "visual" tests, i.e. the tests that can be visually understood even by non-experts, because the game is actually visual. To summarize, the suggestion were:
  • abstractions;
  • visual tests;
  • test first.
3. Since most of the groups followed the standard approach, where the nouns were used to determine classes, it was suggested to think more about verbs and to build classes around them. For example, the main class may still be the Game class, but we should think primarily of its actions that are calculateNextGeneration() and render(). These methods can by directly tested by visual tests (draw a game before and after one step of evolution and compare these two instances) and then implemented. So the suggestions were:
  • verbs;
  • methods <= 5 lines, classes <= 3 methods.
4. Ping-pong session: one developer writes a test, another one implements it. After some time developers change the roles. Developer that writes tests usually thinks of the trickiest tests he/she can write.

5. After the previous session the code was not deleted but each group summarized the advantages and disadvantages of their code on the paper. Then the groups changed the computers. Thus each group was given a code by another group and a summary of its strengths and weaknesses. The task was to improve the code.

6. Each group could choose one of the following restrictions:
  • change a programming language;
  • do not use the if construction;
  • do not use the inheritance (?).

To my opinion, the event was extremely useful and it is a pity that it happens only once in a year. I think a week of such training may improve one's programming skills considerably and, in fact, there are many companies offering such courses for a huge amount of money. So all in all I would recommend everybody to participate in this event at least once.

Комментариев нет: