Uncle Bob’s tweet from a few weeks opened my eyes to the value of practice in honing my development skills, and led me to read a lot more about practicing and code katas. One of the things I love about having a kata, like the prime factors kata, is that you can focus on different skills and techniques each time through. You can do it in different languages, with different testing frameworks, using different text editors or build systems, on different operating systems, etc. I’ve done it a few times in the last few weeks, mostly in C++ (my current language for work projects). But I’ve used Visual Studio, vim, my work’s build environment, and other variations. I still haven’t used a decent testing framework, but that’s one I want to add.
Having gone through the prime factors kata a few times now, there are some changes that I feel should really be made near the end. Ok, the rest of this post isn’t going to make much sense until you at least read through the prime factors kata. Go do it now.
Commenters rightly pointed out that having the additional
if (n > 1)
clause added in test 4 isn’t intuitive and violates the TDD principle of just adding enough code to make the tests pass. But they then added the caveat that without it the step to loops and the candidate variable in test 7 is pretty big for the refactoring step, mostly in terms of the mental leap. I agree.
But if you really do the easiest thing you can as you add tests, you don’t run into that problem at all. The key is when you get to the test for finding the prime factors of 9 (i.e. the seventh test in the slides). The slides have you first creating a variable, candidate, to represent the number 2. This may makes sense as a refactoring step done before writing this test, but lets ignore that for now, and assume you haven’t done it. Then the easiest way to get the seventh test passing is just to copy the entire while loop below itself and change the 2’s to 3’s. Not only is that dead simple (Ctrl-C, Ctrl-V), it also makes the following steps much more obvious. At this point it’s easy to see how important the candidate variable is, so you create it, and increment it between the two while loops. Then the two while loops are identical so you just nest them inside another while loop. The remaining refactoring work to for loops is the same as the slides.
Jeff Atwood recently discussed
Of course, if you want to get more done in the morning running probably isn’t going to cut it, though it might. The key is to find something that is important to you that you’re not prioritizing like you should. For me, it was running. For you, it might be photography, or practicing an instrument, or working on a coding project on the side, or riding your bike, or reading great literature (or not so great literature), or woodworking, or whatever. The main thing to recognize is that when you put your priorities in the right order, life is just smoother. The important things get done, the less important things are more clearly less important, and you’re happier about everything you do. By starting your day with the “first things first” you set the tone for the whole day. And anticipating that each night can make it easier to prepare accordingly. I’ve started getting all my running gear ready each night, and I’m going to bed earlier so that I’m ready to go when the alarm goes off.
So, my last post was all about how I’m trying to become more productive by learning a set of keyboard shortcuts that I can use for faster text/code editing. In this post, I’m going to argue against the premise that it could actually make you faster. The reasons I’ll outline include opportunity costs, lack of portability, anything else? Well, we’ll see, won’t we.
It’s time to buy a new phone. One of the cool benefits at Microsoft is discounts on phones and phone plans from most major carriers. So when my contract is up I go back to the discount web site to see what the latest deals are and if I should get a new phone. My current phone is a T-Mobile SDA that is falling apart because I dropped it when running across a parking lot in the rain. It’s a great little phone, but it would be nice to have one without a dorky rubber band around it. However, I have noticed other people with pretty beat up SDAs, so they must be reliably durable. However, having used it for a year and a half now, there are definitely some things I don’t like about it.
Charlie Munger and Warren Buffett often talk about companies with “moats” or with some intangible asset that makes it very hard for other companies to effectively compete with them. Coca-Cola’s brand is their moat. The network effect has created an amazing moat for Microsoft around their operating system business. Google has a similar network effect moat around their advertising business. While I have almost always heard moats discussed in a business context, I was considering Munger’s “multi-disciplinary” approach recently and realized that moats apply just as well to individuals and the success that they can achieve.