Angel \”Java\” Lopez on Blog

July 29, 2013

End Of Iteration 2013w30

Previous Post
Next Post

A summary of the past week:

Smalltalk Intro

A work in progress presentation at:


First version, it can mutate a source code file, and then run any command (usually the tests)

All written using TDD


Object operations (add, subtract, etc..) a la Visual Basic.NET. I published it at Nuget:

Smalltalk Samples

My first published code, as fileouts and as a FileTree repository:

I also published on see!/~ajlopez. For using Git/GitHub and FileTree, see:


A Prolog interpreter in JavaScript/Node.js. I have atom, variable, facts, base, partial unification. I should work on rules, parser (Edinburg syntax) and full unification algorithm:

Again, all written using TDD.

TDD Rocks!

I published a new video:

TDD Rocks! SharpBase in C#

showing my TDD workflow building a simple in-memory database.

Private Projects

I worked on two private projects: one having an in-memory OLAP cube, and the other was a simple but powerful use case implementation, involving a Single Page Application (all model at browser).

More fun is coming!

Angel “Java” Lopez

July 14, 2013

TDD Kata (6): Bulleyes

Previous Post
Next Post

At Google Code Jam, Round 1A, I found this problem:

The bull eyes problem: Mary should paint a series of concentric circle, given a radius and an initial amount of paint. The problem is: given r and t (the radius and the amount of paint) how many circles of width 1cm Mary can pain?

I wrote my solution using TDD, but after a first thoughts, I coded a solution using a formula, see:

The commit history at:

At the beginning, I had an algorithm that depended on a function that calculates the amount of paint needed to paint a circle of radius r. But then, I replaced it by other algorithm, that directly returns the count of circles that Mary can pain, given an initial radius and paint quantity. All my tests continued to be in green.

As in other Google Code Jam problems, I didn’t write the console program using TDD. I put my focus on the right algorithm. In this case, it was enough to have a general formula that solves the problem.

Keep tuned!

Angel “Java” Lopez

July 1, 2013

End Of Iteration 2013w26

Filed under: .NET, C Sharp, JavaScript, Open Source Projects, Programming Languages, Python — ajlopez @ 9:03 am

Previous Post
Next Post

These were my activities in my open source projects, 2013 week 26th:

Talk: Intro to Python

I’m completing my presentation, using reveal.js

Python Programming Samples

I added minimal programs, a la Hello, World, a Flask sample, and a Django sample


I started a task runner, in C#. I want to automate some steps in a simple way. As usual, it is being written using TDD:

Learning Python

I did minimal changes to my Spanish page tutorial


I updated the grammar/parser generator, to have a parser that pursues the reduction of a term.

AjLisp in JavaScript

I fix a test, minor change. I want to use it in the development of a Node.js/(Express maybe) dynamic site, using Lisp

Most of the week was dedicated to prepare my Python intro talk. I guess I will have more time for programming in the next week. I should to prepare a talk Intro to Smalltalk, for July 1st, Buenos Aires.

Keep tuned!

Angel “Java” Lopez

June 30, 2013

TDD Kata (5): Tree Search

Filed under: .NET, Agile Software Devevelopment, C Sharp, Test-Driven Development — ajlopez @ 3:28 pm

Previous Post
Next Post

Some months ago, I read this message in a TDD list:

Implementation of game tree search using TDD

I read:

I am trying to use TDD to implement game tree searching but I am running
into some issues.Using C#, MS Test and Rhino Mocks.
My requirement is to traverse a tree to a specified depth and find the
maximum value of the nodes at this depth. If a path ends before the
specified depth then the value of the last node in the path should be
Sample usage looks like this:
var depth = 5;
var tree = new GameTree();
var treeSearch = new TreeSearch();var maxValue =
treeSearch.FindMaxValue(tree, depth);

The first tests to implement:

* A search to depth zero should return the value of the root node
* A search to depth one with no children should return the value of
the root node
* A search to depth one with one child should return the value of the
* A search to depth one with two children should return the highest
value of the two children
* A search to depth one of a tree with depth two should return the
maximum value at depth one

All right, but:

Up to this point the tests are simple enough and mocking of the tree is
simple. The last test starts driving towards a depth first tree
traversal.Now I start on depth 2 tests which should drive the rest of
the tree traversal algorithm:
* A search to depth two should return the maximum value at depth two
I decided to mock a complete binary tree with depth 2

The problem is the use of mocks: it complicates the solution. So, I started to solve the problem, without mocks, simply using a tree implementation to use as a base for other tests:

The solution is simple:

You can see the history of development at:

All tests are green:

Lesson learnt: some times (many times ;-) is easier to implement something concrete than build a mock. The tree I implemented could be refined, could be the base for an interface extraction, or could be implemented in other ways. But it served as a base for our search algorithm, using TDD.

Keep tuned!

Angel “Java” Lopez

June 23, 2013

End Of Iteration 2013w25

It’s the end of my personal weekly iteration on programming. Today, I started to write down an “end of iteration” post. My public work:


I updated the samples, and started to write some test, to learn how it could be tested. For me, it is an exploration spike, but it’s time to learn how to write Express applications using TDD. The below example uses MongoDB:

Learning Java

My GitHub pages in Spanish. I updated the intro page:


I updated my Forth-like compiler to JavaScript. It’s in a good state, written using TDD. Inspired by project fjs, it’s an idea I had for years: write a Forth intepreter. Now, this project is a compiler. After writing CobolScript compiler, I have the resources to write a Forth one. The primitives are not the same, i.e., the operators are the JavaScript ones. I hope to add interaction with host language (JavaScript, Node.js) and async call support.


Operators for .NET objects. I had to write this project to give support of arbitrary objects operators. In other projects, I use Microsoft.VisualBasic.CompilerServices, but apparently there is no support in Mono for such methods. For now, I have binary arithmetic and compare operators implemented. It is used in Mass programming language. I relies on code generation via AjGenesis, to avoid to write all the type combinations.


I added the new operators from ObOps, and now the project should compile in Mono. I did a big refactor: change the scope rules, to adopt a JavaScript-way using var and function hoisting. Thanks to TDD, the refactor ran smoothly.

There is an assert module, to start writing Mass using TDD:

First tests:

Additional modules will be hosted in NPM.

Talk Intro to Python

I started to write my next talk presentation:

Only two slides ;-). But it was a good user experience, my first time using Reveal.js. Good support for markdown and code highlighting. No preprocessor needed, simply write the HTML file.


I had the idea of write a PEG (Parsing Expression Grammars) in JavaScript, see (there are links). But I started this new project, realizing that my previous lexers and parsers are faces of the same coin. Now, I have a generic parser, based on rules that detect parts of the code (integers, string, names, etc…)


Before SimpleGrammar, I started a C# project, having a generic lexer/tokenizer and a generic parser. But after my experience with SimpleGrammar, I refactored the code to have a generic parser with detection rules.

TDD in Python

My first Python experiment using TDD, using simple import unittest.

AjLisp in Python

After my first experience with unittest and Python, I started to write a new version of AjLisp, this time in Python. It is WIP, you can see my commit by test at:

I’m using Python 3.3 on a Windows 8 machine.

A lot of fun ;-)

Keep tuned!

Angel “Java” Lopez

June 2, 2013

New Month’s Resolutions: June 2013

Filed under: .NET, C Sharp, NodeJs, Open Source Projects, Programming Languages, Python, Ruby — ajlopez @ 10:55 am

Review of my May’s resolutions:

- Update Mass [complete] repo
- Update RubySharp [complete] repo
- Give a talk, Intro to Ruby [complete] post, repo
- Update AjGenesis [complete] Node.js version repo
- Update ClojSharp [complete] repo
- New posts about Mass [complete] post, post, post
- New posts about Distributed Applications and Node.js [complete] post

Additionally, I was working on:

- Start Eternity in JavaScript [complete] repo
- Start Learning Python in Spanish [complete] repo
- Update AjSharp [complete] repo
- Write first version SimpleJsonHtml [complete] repo

Resolution for this new month, June 2013:

- Update Mass
- Update RubySharp
- Update PythonSharp
- Update ClojSharp
- Update AjSharp
- AjGenesis Node.js examples
- Update Learning Ruby
- Update Learning Python
- Write a Node.js/Express/MongoDb sample
- New posts about RubySharp
- New posts about TDD
- New posts about Mass

So much fun! ;-)

Keep tuned!

Angel “Java” Lopez

May 25, 2013

Mass Programming Language (4) Lexer and Parser

Filed under: .NET, C Sharp, Mass, Open Source Projects, Programming Languages — ajlopez @ 10:38 am

Previous Post
Next Post

In the Mass programming language implementation, I have an enumeration and a class:

A token represents a word of code to be processed. Lexer is in charge of separate the code in words/tokens. And Parse takes that token stream and returns expressions and commands:

Lexer constructor receives a string:

public Lexer(string text)
    this.text = text;

This string is processed to be separated into tokens. Notice the lexer distinguish between operators (like +) and separators (like parenthesis). It take into account the end of line as a token, too (in other programming language, like C, the end of line is simply a blank space). The main method of Lexer is NextToken that returns the next token in code text. In some situations, it is needed to save a consumend token, so there are methods like PushToken and its variants.

Internally, Parser manages a Lexer. You can get the next command calling ParseCommand method, and the next expression using ParseExpression. When the text is exhausted, those methods return null.

I should modify Lexer to consume a text stream, instead of a string, so it could process an input, like console.

I should think about unifying commands and expressions, a la Ruby where all is an expression.

Keep tuned!

Angel “Java” Lopez

May 10, 2013

TDD Kata (4): Lawnmover

Previous Post
Next Post

In the previous post, I commented about by experience at pre-round at Google Code Jam.

The exercise B was Lawnmover:


Alice and Bob have a lawn in front of their house, shaped like an N metre by M metre rectangle. Each year, they try to cut the lawn in some interesting pattern. They used to do their cutting with shears, which was very time-consuming; but now they have a new automatic lawnmower with multiple settings, and they want to try it out.

The new lawnmower has a height setting – you can set it to any height h between 1 and 100 millimetres, and it will cut all the grass higher than h it encounters to height h. You run it by entering the lawn at any part of the edge of the lawn; then the lawnmower goes in a straight line, perpendicular to the edge of the lawn it entered, cutting grass in a swath 1m wide, until it exits the lawn on the other side. The lawnmower’s height can be set only when it is not on the lawn.

Alice and Bob have a number of various patterns of grass that they could have on their lawn. For each of those, they want to know whether it’s possible to cut the grass into this pattern with their new lawnmower. Each pattern is described by specifying the height of the grass on each 1m x 1m square of the lawn.

The grass is initially 100mm high on the whole lawn.

I solved it, see:

As usual, the commit history by test:

I could solve the first small set provided by Google. But I failed with the big set, because my algorithm was not efficient enough. The big set should be solved in 8 minutes, and if you cannot, there is no other chance. My initial algorithm (see comments) attacked the largest number in cells. My second algorithm switched to start with the minimal numbers (my first guess was that both algorithms had the same time, but I was wrong). I learnt: some problems in Google are hard to test by hand, we don’t have the use case (input and expected output), that is the main difficult.

More katas are comming.

Keep tuned!

Angel “Java” Lopez

May 8, 2013

TDD Kata (3): Tic-Tac-Toe-Tomek

Previous Post
Next Post

Two weeks ago, I participated of the pre round of Google Code Jam. Exercise A was TicTacToeTomek:


Tic-Tac-Toe-Tomek is a game played on a 4 x 4 square board. The board starts empty, except that a single ‘T’ symbol may appear in one of the 16 squares. There are two players: X and O. They take turns to make moves, with X starting. In each move a player puts her symbol in one of the empty squares. Player X’s symbol is ‘X’, and player O’s symbol is ‘O’.

After a player’s move, if there is a row, column or a diagonal containing 4 of that player’s symbols, or containing 3 of her symbols and the ‘T’ symbol, she wins and the game ends. Otherwise the game continues with the other player’s move. If all of the fields are filled with symbols and nobody won, the game ends in a draw. See the sample input for examples of various winning positions.

Given a 4 x 4 board description containing ‘X’, ‘O’, ‘T’ and ‘.’ characters (where ‘.’ represents an empty square), describing the current state of a game, determine the status of the Tic-Tac-Toe-Tomek game going on. The statuses to choose from are:

  • “X won” (the game is over, and X won)
  • “O won” (the game is over, and O won)
  • “Draw” (the game is over, and it ended in a draw)
  • “Game has not completed” (the game is not over yet)

If there are empty cells, and the game is not over, you should output “Game has not completed”, even if the outcome of the game is inevitable.

An input file can be downloaded with different board positions, and our program should generate an output file with the results: X won, O won, tie, or the game is not finished, yet.

I wrote my solution using TDD, you can see the result at:

The commit history, with test granularity:

It was a simple exercise, and well adapted to TDD. Google accepted my solution to a small input file, and to a big one too. I should write about the other exercises (B, C, D) that are a bit more complicated for TDD:

- Each problem should be solved quickly. With TDD, you could implement an algorithm but it could be not efficient.

- The algorithm to implement is not evident, and you should write the increasing difficult input cases.

- Sometimes, given an input state, it is hard to reach (even by hand) a right output solution. Many of my attempts were rejected by Google, without much info about what is the right solution, so you must review manually each result.

Keep tuned!

Angel “Java” Lopez

May 6, 2013

TDD Kata (2): Alien Language

Previous Post
Next Post

Some week ago, Google Code Jam was mentioned in Spanish list TDDev.  One of the  past problems of this contest was Alien Language.

After years of study, scientists at Google Labs have discovered an alien language transmitted from a faraway planet. The alien language is very unique in that every word consists of exactly L lowercase letters. Also, there are exactly D words in this language.

Once the dictionary of all the words in the alien language was built, the next breakthrough was to discover that the aliens have been transmitting messages to Earth for the past decade. Unfortunately, these signals are weakened due to the distance between our two planets and some of the words may be misinterpreted. In order to help them decipher these messages, the scientists have asked you to devise an algorithm that will determine the number of possible interpretations for a given pattern.

A pattern consists of exactly L tokens. Each token is either a single lowercase letter (the scientists are very sure that this is the letter) or a group of unique lowercase letters surrounded by parenthesis ( and ). For example: (ab)d(dc) means the first letter is either a or b, the second letter is definitely d and the last letter is either d or c. Therefore, the pattern (ab)d(dc) can stand for either one of these 4 possibilities: add, adc, bdd, bdc.

I liked the problem. See in the page that we should read an input file with the words and patterns to process. We can download input files from the problem page, and upload an output file with our solution, generated by our problem. Then, Google will return if the answer is correct or not. So, I wrote a solution using  TDD:

You can read commit history, with test granularity, at:

One of the latests things I did was to refactor the detection of words that match a pattern. I could improve it, maybe using a word tree instead of a list of words, as I did in SimpleBoggle.

At the end, I wrote a console program that accepts an input file and writes an output file, as Google contest requires. I downloaded a big input file from Google, processed it, and uploaded the solution. Google answered: OK:

TDD rules ;-)

Keep tuned!

Angel “Java” Lopez

« Newer PostsOlder Posts »

The Shocking Blue Green Theme. Blog at


Get every new post delivered to your Inbox.

Join 65 other followers