TDD, Unit Tests and the Passage of Time

Many programmers have a hard time writing good unit-tests for code that involves time. For example, how do you test time-outs, or periodic clean-up jobs? I have seen many tests that create elaborate set-ups with lots of dependencies, or introduce real time gaps, just to be able to test those parts. However, if you structure the code the right way, much of the complexity disappears. Here is an example of a technique that lets you test time-related code with ease. Continue reading

Automatically Include Revision in Log Statement

When there is a problem with your software, the first thing you usually ask for is a log showing what happened (provided you write debuggable code), and the version of the software that was running. But it is easy to have the revision of the software automatically added to the log. Continue reading

7 Ways More Methods Can Improve Your Program

A lot of code I come across consists of relatively few, but long, methods. The code does what it is supposed to do. However, it could be improved a lot. Refactoring to use more methods can produce better structured programs that are easier to understand, easier to modify, easier to test and easier to debug. Below are 7 reasons why using more methods can be a good idea.

Continue reading

LinkedIn – Good or Bad?

I have read a couple of blog posts about LinkedIn recently. “Is LinkedIn Cheating Employers and Job Seekers Alike?” is criticizing LinkedIn for charging job seekers to appear “at the top of the list” when applying for a job. “LinkedIn Spam (?) and Recruiters: A Guide for Geeks” has some good advice on how to interact with recruiters on LinkedIn. These among others made me ponder the question: Is LinkedIn good or bad? (and Betteridge’s law notwithstanding, the answer is not “No”). Here is my take: Continue reading

Great Programmers Write Debuggable Code

All programs need some form of logging built in to them, so we can observe what it is doing. This is especially important when things go wrong. One of the differences between a great programmer and a bad programmer is that a great programmer adds logging and tools that make it easy to debug the program when things fail.

When the program works as expected, there is often no difference in the quality of the logging. However, as soon as the program fails, or you get the wrong result, you can almost immediately tell the good programmers from the bad. Continue reading

SET Card Game Variation – Complementary Pairs

I recently got an e-mail from Michael Sherman, a teacher in New York. He had developed a variation of the card game Set called Complementary Pairs. This is how he described it:

“We have Set competitions at the school where I teach, both as individual time trials and as head-to-head matches. When many students at my school became capable of finding sets very quickly, I developed what I called C.P. Set (Complementary Pairs) to slow them down a bit and reduce the number of simultaneous calls in the head-to-head matches.  The idea is to find two pairs of cards that both require the same 3rd card to complete a Set. The completing card does not need to be on the board; only the four cards forming the complementary pairs are picked up.” Continue reading

Programmer Productivity – Interruptions, Meetings and Working Remotely

In my previous post on what programmers want, I ranked working from home low on the list. Several commenters value working from home higher, and K (not his real name) added a link to a great TED talk given by Jason Fried (of 37signals) on why it is hard to get any work done at work. Jason starts with the observation that programmers need long stretches of uninterrupted time in order to get stuff done, and goes on to recommend avoiding meetings, and minimizing interruptions by using chat and e-mail instead of direct communication. While I agree with the meetings part, I think there is more to consider regarding interruptions. I also value face to face interactions more than he does. Continue reading

What Do Programmers Want?

I got an e-mail last week from three students at Halmstad University doing a three month project on what programmers want in a job, and how companies can attract talented programmers. Here are my answers to their questions, in order of importance. Obviously people have different preferences, so it would be interesting to hear what items you agree and disagree with, how you would rank them, and what you think is missing. Continue reading

Coursera course review: Algorithms: Design and Analysis, Part 2

I recently finished the Coursera course Algorithms: Design and Analysis, Part 2 by Professor Tim Roughgarden of Stanford. I’ve already reviewed part 1, and here are my thoughts on the second part.

The main theme of part 1 was the divide and conquer paradigm. In the second part the main themes were greedy algorithms, dynamic programming and NP-Complete problems. The lectures were excellent, with clear and easy to follow algorithm development and proofs. At six weeks, it was one week longer than part 1, and I found it quite a bit harder than part 1. Here’s more on each part. Continue reading

Blog stats for 2012 (by WordPress)

The WordPress.com stats helper monkeys prepared a 2012 annual report for this blog.

Here’s an excerpt:

About 55,000 tourists visit Liechtenstein every year. This blog was viewed about 170,000 times in 2012. If it were Liechtenstein, it would take about 3 years for that many people to see it. Your blog had more visits than a small country in Europe!

Click here to see the complete report.