Bowling game Kata in Erlang reloaded
So my first solution to the Bowling Game Kata was wrong! Well, a good chance to learn something. ![]()
Let's try to solve the problem again.
I added the last test to my test suite, which shows the previous bug:
Then I modified the code this way
The code now is not so clear, but it passes tests! What I learned from this exercise? Well, Ron Jeffries said:
I would bet, though, that if we were to take some set of problems that can be solved in a natural fashion both recursively and iteratively, and had a bunch of programmers write both versions, they would have more trouble with the recursive ones, on the average.
My experience seems to confirm his opinion, even if I should consider that it's more than twenty-five years that I solve problems iteratively, while I came to use recursive solutions only a few times. Thus, perhaps my way of seeing problems is not accustomed to think in a recursive fashion, and it requires some more time to get into this way of thinking. So, let's do more Erlang exercises!

Franco Lombardo:
Here is a comment from Matteo Vaccari:
Hi Franco! Two things:
- a tail-recursive solution is just like a while loop in a different syntax
- you can gain a lot of readability in functional languages if you think of composing functions like building blocks.
Have fun!
And here is my answer:
Matteo,
I forgot to mention that I chose not to use a tail-recursive solution in order to improve readability, since the problem involves a small amounts of recursive calls.
I’ll try to improve my functional programming skills using your advice: thanks!
1 Luglio 2010, 5:52 am