Friday, February 23, 2007

Use the braces, stupid!

Upon further reading of Programming in C (3rd ed.) by Stephen G. Kochan, I have a discovered a flaw in this otherwise excellent book: the author doesn't always use braces around the bodies of if/else statements and loops. On the whole, I can live with this defect. However, as someone who has done research on the causes of bugs in software, I can confidently say that omitting braces causes bugs. For example:
for (j = 0; j < m; ++j)
for (i = 0; i < n; ++j)
f();
g();
The call to g() is not in the body of either loop. This may seen contrived, but FindBugs found several examples of similar bugs in a Java library that shall remain nameless.

A bug in released software can easily cost thousands or tens of thousands of dollars to fix; using braces consistently eliminates a common cause of defects.

Tuesday, February 20, 2007

Programming in C

I've been evaluating textbooks to use in the intro programming course I teach in the fall, and I think I've found the one I'm going to use: Programming in C by Stephen G. Kochan. I've read the first few chapters, and I really like the style: concise, clear, with code examples that are short but illuminating. I have a huge pet peeve with programming textbooks that are 800 pages long and are so filled with unnecessary detail that you can't see the forest for the trees. (I won't mention names, but I'm sure you know what I'm talking about.) I actually evaluated K&R (2nd ed.), but I was quite disappointed. I would not want students (or anyone really) to write code in that ultra-terse, cryptic style. The Kochan book gets it just right: focused prose, clear code with meaningful (but not excessively long) identifiers.

Parallel to this discussion, of course, is the question of why I want a book that just does C (as opposed to C++). There are two main reasons. Students need to be exposed to low-level concepts like pointers and addresses, so either C or C++ needs to be in the curriculum. Second, C++ is a dangerous, bloated mess of a language when you get to the object-oriented features. My experience has been that students' initial transition from C to Java is a fairly easy one, especially if they have seen structs and are comfortable with the concept of encapsulation. Once they know Java, the sky's the limit; due to the safety features, clean object model, and availability of outstanding development tools like Eclipse, it really is an excellent language for CS education.

VirtualBox

I found out about VirtualBox from a post on osnews.com which linked to a review. It's an free software (GPL) virtual machine that runs on Linux and looks quite spiffy. Benchmarks in the review suggest about a 2x slowdown on a mixed CPU/disk workload. I could live with that if meant I didn't have to boot into Windows any more. Note to self: try installing this!

Meanwhile, KVM (Kernel-based Virtual Machine) seems to be gaining momentum, but it requires hardware-level virtualization in the CPU it runs on. Maybe I'll buy a real computer this summer and I can try it out.

Wednesday, February 14, 2007

Nothing to see here, move on

This post is just here to fulfill my legal obligation as an internet user to have a blog where I post my worthless thoughts and opinions.