Problem:
A week ago, I came across a programming exercise to create a String Calculator using TDD. Since I don't understand TDD much at all, I watched some examples and decided to give it a shot myself (the beginner part). I completed it a few times since then, and today I recorded it. This was the result:
Watch my solution for the String Calculator here (10 minutes):
<!-- m --><!-- m -->
- use fullscreen
- forgive the AHK crashes, the java web screen recorder caused computer slowdowns
- feel free to pause, rewind, etc to follow with my thought processes
My Comments:
- I first learned about TDD maybe 6 months ago from the Bowling Game Kata. I did a little bit of reading but wasn't convinced that the benefits would outweigh the additional coding. But, there is a definite comfort in knowing that I could potentially have the freedom to completely rewrite code and ensure that the rewrite is correct if all the tests pass. This is good motivation to implement some type of testing into my personal project. But, since it wasn't designed with testing in mind right from the start, I doubt I'll be able to integrate this type of testing into my app. Besides, the global-friendliness of AHK also makes it hard, especially when I've taken no care in that regard. Maybe when AHK v2 is ready and I get my head around its objects I will be able to do it better.
- I don't like that my final solution included a repetitive "Loop, Parse" for both the sum and to check the negatives. In my first attempt at the kata, I put these together in one Loop. Later though, that didn't work when I tried to refactor the bits into their separate single responsibility functions.
- AHK has no exception handling, so I had to return -1 for failure and popup a messagebox with the error when negatives are inputted. Not very elegant. Are there alternatives?
- In the name of speed, I skipped some tests that should have been done that I had forgot. In previous run-throughs, I included these types of tests as well when testing the custom delimiter functionality. With the recorder going, I was feeling some pressure and forgot
Test_ShouldAllowCustomDelimiter() { assert( myadd("//;`n1;2"), 3) assert( myadd("//$`n1,2`n3$4") , 10) assert( myadd("//-`n1-2"), 3) }
- Finally, running through this kata opened my eyes to just how slow I am when I write code. I am a decent touch typist, around 90wpm, but there were a few things that I learned to do as a result of this exercise:[*:kg3ilnc2]Get autocomplete and intellisense calltips working in Notepad++. This was a huge benefit, and will save me lots of time from going from editor to website help and back to editor. I tried majkinetor's ISense script but it was quirky for me. The autocomplete in Notepad++ works ok, but it slows the editor down a bit.
[*:kg3ilnc2]macro hotstrings! Being an AHK user I should be faulted for not using these sooner, but they are great, and never realized their usefullness. I created two hotstrings because of this exercise, one to close braces {`n} when I type the opening, and another to create a frame Test function. If anyone has other hotstring examples to help coding, I'm all ears - I used my build of majkinetor's UTest as the testing framework.
(for newcomers, registration is NOT required to reply, guest posting is allowed on the forum)