It's easy to dismiss this exercise because one is always looking to do bigger and newer things. As a karate student, you're often interest in learning how to do a spin kick or other cool things you see in Kung Fu movies. You probably don't know that if you execute a normal kick perfectly, you can injure your opponent in one shot instead of having to do several poorly spin kicks (which waste energy and time). It's been awhile since I took karate, but if I remember correctly, in order to do a perfect kick, you have to:
- assess the situation which includes your surrounding and your opponent. (You don't want your foot to land on a banana peel after your kick.)
- figure out your opponent weak spot.
- execute the kick from your hip and focus your energy on the kick to create the most impact.
- prepare for your opponent defense/counter attack.
That is what I hope to achieve in code katas. I want all the good programming practices (e.g. write test first, write good variable names) to be ingrained in me so that it becomes second nature. I should feel a nudge whenever I start writing bad code.
The second part to practicing katas is that you often find new ways of doing things. The first time I did the prime factors kata, I was really slow. I struggled to write the test and write the simplest code to make the test pass. I had to watch Robert Martin do the kata, several times, to see how he came to the solution and try to emulate that.
After practicing the kata for a week, I'm beginning to feel its effect on me. I feel a nudge when I write code without a test. I begin to see what kind of test I should create to make the algorithm better. I still haven't perfected my kata yet, not that there is a perfect solution. Programming is an art, as they said. There is no perfect solution. However, I still haven't arrived at the solution I'm satisfied with. So the goal is to practice a kata a day. And only one kata a week, which means I will be doing the same kata at least five times. And every time I do the kata, I have to think of better way to write it.
0 comments:
Post a Comment