Here, at long last, is a recording of the Prime Factors Kata in Ruby, done to the tune of the Flower Duet from Lakme’. This version is much more polished than previous versions, though is still not perfect. It will take many more weeks of practice to perfect.
Many things have changed since the last version. Note the refactoring of the tests, and the elimination of duplication of the ‘it’ clauses. Note also that I succumbed to the temptation to play “golf” and reduce the line count by using the ‘and’ conjunction in way that some might consider bad style. Finally, there is a sequence at the end where the focus changes from correctness to performance.
| Screencast.com | |
| Vimeo |
Prime Factors Kata in Ruby, Flower Duet, Lakme’ from unclebob on Vimeo. |
| Viddler | |
Impressive!
My that was a lot of cheering at the end.
How this can be watched?
Tried few browsers, installed QuickTime…
A simple video, please?
Varely,
We are working on uploading it to vimeo. Should have it within a couple days.
Yes, very enjoyable to watch. I’d love to see more.
And yes, the full minute of cheering at the end could be reduced.
I enjoyed watching that, thanks!
There was only one thing that I thought could be improved. When you refactor the array of numbers and their factors from [1, []] to ['1', []], evaling the string feels like too much too soon. After all, it is only when you add ['2*3*5*7*11*13', [2,3,5,7,11,13]] that you actually need to eval the string.
On the other hand, it did add some narrative to the kata. I was wondering ‘Why did he do that?’, and then when I saw the ‘2*3*5*7*11*13′ string I went ‘Aha!’. Perhaps it was intentional…?
Nicely done, but the East Village Opera Company sings terrible French.
That was really beautiful.
Yeah, I found that use of ‘and’ a little confusing at first.
I had to do a double take.
While I really enjoyed the music, it would have been super cool to hear you narrating your thought process.
You went into a couple of steps in a sure-fire mode.
Especially when you introduced the performance improvement.
I thought to myself, How did he came up with that?
(maybe it’s a well known algorithm that I am not aware of)
Again, thank you for sharing.
It was awesome
Uncle Bob… Are you really not using Quicksilver?
I _do_ use Quicksilver. What am I missing?
The sqrt(n) thing at the end is to improve performance. Why not evaluate sqrt(n) _once_ (outside the while loop) instead of every time?
Nice work. Shows a benefit of BDD I hadn’t really grokked before.
[...] Martin hat die Code-Kata sogar zu Musik vorgeführt und damit Programmierung in die Nähe einer Kunstform [...]
Beautiful, really enjoyed watching it!
I’d suggest to use %w{ 2 [2] etc… }.collect{|x|eval x}.each_cons(2) though, to save all the bracket and comma clutter.
Very well done. It was fun to watch the extra tests and tweaking after the algorithm was already established. And deleting the files made for a dramatic ending.
[...] with code? Can you practice to code a certain piece of software over and over until it becomes art? Uncle Bob certainly thinks so. I started doing some katas a few months ago but a question was still nagging me : do they really [...]
[...] you read yesterday’s post and wonder where you can find motivation to start to practice, look at this. It’s a screencast of Uncle Bob doing a Code Kata. A simple exercise, but if you look at the [...]
[...] of code into a cleaner form. He also provides on his website a presentation and even a video demonstrating the process of doing test-driven [...]
[...] was inspired by the "katacasts" of Uncle Bob as well as my friend Johannes, and decided to do one of my own. I chose a very simple task for this [...]
[...] with code? Can you practice to code a certain piece of software over and over until it becomes art? Uncle Bob certainly thinks so. I started doing some katas a few months ago but a question was still nagging me : do they really [...]
[...] you read yesterday’s post and wonder where you can find motivation to start to practice, look at this. It’s a screencast of Uncle Bob doing a Code Kata. A simple exercise, but if you look at the [...]
The tests here feel a little artificial. You can create the tests given the definition of “prime factors”. For all n >= 2, the factors must:
Be prime
Multiply together to get n
Now in almost on time you can generate thousands of test cases.
Two other points, your code might want to return an undefined for n <= 0, and the prime factors of 1 are [1].
Interesting to watch though!
[...] I started my first session with the Prime Number kata. I like this kata since it is really simple, can easily be done in less than 30 minutes (closer to 10 once you’ve done it a few times) and I learned a few useful tricks in ruby by watching this kata permormed by Uncle Bob on Katacast. [...]