Earlier tonight Carlos tweeted this:
I may have just âtest drivenâ my first official Ruby problem (cc: @maxjacobson).
Kind of a cool experience. đ đ
https://t.co/vIza7c0J3I
— Carlos Lazo (@CarlosPlusPlus) March 17, 2015
Nowhere in there does he specifically ask me to provide my take on that problem, but I did anyway. I donât know why.
The problem is, I think, to write a reverse polish notation calculator in Ruby. Carlos used TDD to drive his solution. I looked at it and thought it was cool, and then I wanted to do the same thing, and I made a video, because I am a ham.
Here it is:
It is very long. There are a few moments where I removed sound to take away coughs. I might have missed some. I probably did!
Youâll hear every thought that passes through my mind as I arrive at a solution, which I pushed here: https://github.com/maxjacobson/calculator. A lot of it is me struggling to understand the very premise of the notation, which confused me perhaps too much?
Using tests helped me get this working because when it wasnât working, I wasnât sure which part wasnât working, and I was able to add more tests to describe the parts, until I knew which parts were behaving how I expected and which werenât. Thatâs really helpful. Accomplishing that meant extracting some of the responsibilities into a separate, small, testable class, which I think is a good example of lettings tests drive the design of your code. Ultimately the implementation of that class is kind of awkward and not great, but itâs also really contained and could be easily rewritten because there are tests to catch mistakes in the refactoring.
đ