Last week a friend of mine (one of the developers of Quares) told me an idea about an iPhone game. It was a rap battle game and he wanted my advise, due to my expertise in emceeing 😉 His first approach was to have a kazillion pre-recorded raps and then assign them weights, points, whatever… Soon we saw that it’d be better to generate rhymes but it seemed a tough job.
Choosing the TDD way
What I found more difficult was to ask the right questions. It’s kind of funny to ask something when you know the answer but the objective was to build the data structure test by test. I based them on the existence of terminals (final text) and non-terminals (tokens that can be substituted for both terminals and non-terminals). From that point, it was easier to start.
My self exam
- As I said before, the key point is to ask good questions. There are many ways to skin a cat and bad tests can lead you in a wrong direction. I need to study other’s people katas to improve this skill.
- Not enough refactoring. I think that I need to be more aggresive in refactoring. Sometimes I don’t feel like a refactor is needed right now, leaving a likely broken window. The same thought about katas applies here.
- Not sure when it’s better to inject dependencies / use composition. In the end it works as this is a simple example but I have to keep an eye on this.
- It’s difficult to create a good grammar. This is not a TDD or development issue but I assure you it’s quite hard.
Craftsman bio generator
After having all my test in a healthy green color and with the ability to substitute non-terminals I decided to have more fun. I’ve created a craftsman bio generator, in case you don’t know what to write in your twitter account.
Here are some examples:
- Co-author of ‘The best practices for Haskell’ and ‘Clean Clojure’ (contributor). Scrum enthusiast, Ruby on Rails expert, father.
- Working at NextLearning, Haskell expert, husband. Likes reading. Writing Ruby on Rails webs for CompuGlobalHyperMegaNet also.
- I write code for NextCoding.com. Prize-Winning author of ‘Developing XP Haskell software’ and ‘Clean RoR’.
I’ve uploaded the generator to my GitHub. All the magic is in the grammar file (bioGrammar.js). You can study how the generation it’s done and if you use it for building your own generation let me know!
- More test cases. I guess there aren’t enough tests. You need one that traverses all the grammar to find errors in that structure prior to begin execution. I did tests only for the code but finding issues in the data is a plus.
- Number / gender concordance. This is planned for the next iteration. Remember that the aim is to have a rhyme generator, but before, if I want to build sentences that make sense I have to add more complexity to the substitution process, taking care of the number and gender of the subjects.
Featured image Argyle Street Joinery (modified)