Dear Programming Job Applicants...

I know this might come as a shock to you, but most programming job applicants suck. I've interviewed my fair share this month, and it'll be a lot easier for all of us if I tell you upfront what I'm looking for.

As a hiring manager, my job is to make sure you can do the job you're applying for. For programming that means you need to be able to program. So when I whip out a laptop in our round-one interview and ask you to write some code, try to hide your terrified expression.

Continue reading "Dear Programming Job Applicants..." »

Is it Worth Teaching Assembly?

This is an open question to programmers: is it worth teaching someone assembly language anymore? My instinctive reaction is "of course," but let me explain why I'm second-guessing that instinct.

The Case For

Back in the 1990's I had my moment of revelation: a pal of mine, a far more experienced programmer than me, showed me how C code compiled into assembly. This was on the Motorola 68K instruction set. I learned to walk through how the stack works, how pointers work, how loops work... it all finally made sense. From that time forward, I've had no fear of C or C++ because I know how the language morphs the code I write into the code the computer sees.

Continue reading "Is it Worth Teaching Assembly?" »

Problem Inversion

Here's a scenario in Windows XP. I print a document. Windows attempts to contact the printer, but something's wrong, then Windows pops up this deceptively helpful-looking message in the task bar:

print error bubble

Okay, so I open the print queue and open the troubleshooter:

print error troubleshooter

Wait a second, you're asking me what my problem is?

This is worse than useless. Windows has inverted the problem, making its problem into the user's problem. Notice the wording: "What problem are you having?" The workflow puts the user in an impossible conundrum:

  1. Windows says there's some problem, but no details on what.

  2. But never fear, the troubleshooter can help!

  3. Troubleshooter asks the user what the problem is. Funny, that's exactly what the user was wondering, too.

This appears to replace the old way of doing things, where a program would display an error message specific to the problem encountered. But now, with some perverse intent of "helping" the user, we've got a generic error message -- "This document failed to print" -- combined with a troubleshooter that doesn't have the first clue about what the problem is.

Adding reCAPTCHA to Movable Type

UPDATE 2007.07.11: version 1.2 released.
UPDATE 2007.08.29: instructions for MT 4.0.
UPDATE 2008.05.01: instructions for MT 4.1.

Joel just clued me in on a new Captcha system called reCAPTCHA. What's different about reCAPTCHA is that they use the verification words to correct OCR mistakes in scanned books. In their words: "About 60 million CAPTCHAs are solved by humans around the world every day.... in aggregate these little puzzles consume more than 150,000 hours of work each day. What if we could make positive use of this human effort?"

They provide PHP code and a WordPress plugin, but I'm using Movable Type here, so I wrote a Movable Type plugin to use this system. Details follow...

Continue reading "Adding reCAPTCHA to Movable Type" »

Boulder/Denver Ruby Group: MapReduce

Here are slides from my presentation at the Boulder/Denver Ruby Group on "Simple MapReduce with Ruby and Rinda." This is much of the same material as my article on the topic, but it focuses on the high points and perhaps better illustrates what's going on. If you were at the meeting and have comments on the presentation, or have time to play with MapReduce, shoot me an email and let me know!

TextMate Command: Reformat C Defines

For the TextMate users out there who write C and C++, here's a handy command for beautifying a bunch of #define lines. I don't know about you, but I'm used to seeing lots of header files with this kind of junk:

#define FOO       1
#define BAR    3
#define BAZ   (FOO + BAR)

What I want is a magic command to line up all the definitions to the column that's the nearest multiple of the tab size, like so:

#define FOO                 1
#define BAR                 3
#define BAZ                 (FOO + BAR)

So here's a script to do that: Download "Reformat Defines" TextMate Command. Source code follows for the curious.

Continue reading "TextMate Command: Reformat C Defines" »

Simple MapReduce in Ruby

Here's a simple version of the MapReduce framework presented in the now-famous Google paper by Dean and Ghemawat. My version of MapReduce is not intended as a usable high-performance framework, but rather as a learning tool. My goal is twofold: first, to learn to write algorithms in distributed/parallel MapReduce style. Second, to see how simply these concepts can be expressed in Ruby.

I use the Rinda framework to distribute tasks to remote workers. This simplifies a great deal of the MapReduce grunt work. The map and reduce code, along with data, is marshaled and sent over the network transparently. Creating a MapReduce job is as easy as creating an object, assigning lambdas for map and reduce, assigning data, then telling it to run.

Continue reading "Simple MapReduce in Ruby" »

Boulder/Denver Ruby Group Presentation

Here are slides from my presentation at the Boulder/Denver Ruby Group last night. It's Ruby-focused "Lessons Learned" based on the project I've been leading this year, the software for Spectra Logic's new disk arrays. Topics covered include embedded vs. Internet web servers, interfacing with hardware and 3rd party tools, text processing, and a lot of Ruby on Windows stuff.

Image::IPTCInfo 1.93

New version of Image::IPTCInfo posted, my Perl module for manipulating IPTC meta-info in image files. This was merging in changes from Brian Carp of Photo Researchers, who has done all kinds of neat stuff with the module. Look for version 1.93 here:

Also wanted to point out a cool script by Paul Archer that uses IPTCInfo for easy and smart keyword manipulation for images:

Why I'm Not a [Insert Language Here] Programmer

I have over a decade of professional C++ experience, but I don't call myself a "C++ Programmer." Am I competent with programming in C++? Yes, very much so. But I refuse to let my skills be pigeon-holed by the language I've historically used. Nor should you.

Use the right tool for the job, the saying goes, and software development is no exception. Programming languages, frameworks, and other tools are the subject of religious-caliber debate but they are just means to a greater end. This article is a call to both programmers and their managers: a good programmer cannot be summed up by the list of tools they use.

Continue reading "Why I'm Not a [Insert Language Here] Programmer" »

Tortured Logic, Visual Basic Style

This from the Microsoft sample code for Remote Web Desktop:

sub OnControlLoad
   set Control = Document.getElementById("MsRdpClient")
   if Not Control is Nothing then
      if Control.readyState = 4 then
         Document.all.connectButton.disabled = FALSE
      end if
   end if
end sub

Not un-convoluted? No.

Ruby Mini-Pattern: Using Blocks To Handle Special Cases

When implementing a generic processing method that needs to handle a special case (for example, in a parser), use blocks to elegantly handle these cases instead of writing the code inline.


This mini-pattern is specific to Ruby, and while my example deals with parsing text, the technique could be useful in other situations.

Continue reading "Ruby Mini-Pattern: Using Blocks To Handle Special Cases" »

Feature Blight vs. Constricting Deadline

What has been described as "creeping elegance" is probably better described as "feature blight," for like a fungus on a plant it gradually elaborates and blurs the true outline of the product while it drains its sap. The antidote to feature blight is, of course, the "constricting deadline." This results in features being discarded in proportion to the time it would take to implement them. It is often the case that the most useful features take the longest to implement. Thus the combination of the blight and the deadline yields software as we know and love it, comprised of bountiful quantities of useless features. -- Jef Raskin

(As quoted in the excellent book Getting Real by 37 Signals.)

Mini-Pattern: Scaling Vector Icons to Small Sizes

Given a vector-based icon system, scale the icon's size and the icon's stroke weight independently for optimal display at both large and small sizes.


Graphical user interfaces with vector-based icons, in particular those which may need display at varying sizes.

Continue reading "Mini-Pattern: Scaling Vector Icons to Small Sizes" »

Mini-Pattern: Making Static Methods Semi-Polymorphic

There are some global mechanisms where it's common to use static (class) methods as a primary API, only to discover later that the mechanism needs requires polymorphic behavior. For example, a logging mechanism may simply use printf() to start with, but later it may require changeable behavior depending on command-line arguments. This mini-pattern shows how to make a static method API polymorphic under the covers.


Applicable in many places using static methods or globals, e.g. logging and factory methods.

Continue reading "Mini-Pattern: Making Static Methods Semi-Polymorphic" »

Boulder-Denver Ruby User's Group

Last night I attended the inaugural meeting of the Boulder-Denver Ruby User's Group. "Meeting" was a term used in the loose sense -- it was more a gaggle of Ruby enthusiasts sitting around tables with beer, chatting about Ruby and other geek stuff. The meeting was held at a brewery, so it was impossible to hear people more than a couple feet away, but as the group shifted around I probably talked with half a dozen others.

Continue reading "Boulder-Denver Ruby User's Group" »

The Ruby vs. Lisp Debate

Lisp has a mystic aura as the "programming language to rule them all," so most hard-core geeks nurture a fascination with it. Paul Graham has written several essays extolling the virtues of Lisp, and indeed he's got reason to talk: he built what is now Yahoo! Shopping with Lisp. His famous Beating the Averages essay describes the experience.

I was curious how Ruby stacked up with the power-user features of Lisp, so I went digging for the inevitable "Ruby vs. Lisp" debate. I use Ruby these days (thanks to Rails) and I've used Lisp before (thanks to Emacs), but I haven't used either extensively enough to call myself an expert. Thus, I was curious to see the experts weigh in.

I must say upfront that my focus is narrow: I'm looking at each for the purpose of building web-based applications. Thus the discussion is not language vs. language, but language + frameworks vs. language + frameworks suited for my purpose.

Following is partly a summary of my research, but mostly a commentary on the debate itself. There's an interesting rift between the two camps, "interesting" not just for their opinions but for their perspectives.

[Update 2006-01-21] Please note this disclaimer I posted in the comments below.

Continue reading "The Ruby vs. Lisp Debate" »

Ruby on Rails, MySQL, and Mac OS X 10.4 Tiger

There's a problem with running Ruby on Rails with MySQL on Mac OS X, and the multitude of web pages I found while trying to fix it were not helping. Worse, they made the WEBrick server flat-out crash. Assuming Xcode 2 and MySQL 4.1.15 are installed in their default locations, here's exactly what I did to finally get running with Rails:

Continue reading "Ruby on Rails, MySQL, and Mac OS X 10.4 Tiger" »



Easy C++ Allocation Tracking

Programmers complain ad nauseum about the lack of garbage collection in C++, and about how hard it is to detect leaks during development. Here's some code which, used in conjunction with good unit tests, will help you quickly detect and isolate leaks.

Continue reading "Easy C++ Allocation Tracking" »

GD Font Rendering Differences

I've noticed significant variations in font rendering when using the GD/FreeType graphics libraries, depending on the platform and font technology used. Here's a visual reference of my observations.

The following tables show buttons created with a PHP script using 2 type sizes. Both TrueType and Postscript (using T1Lib) are provided.

Continue reading "GD Font Rendering Differences" »

The Power of Focused Applications

Most of us engineers have puzzled over Microsoft Word, specifically: how can a word processor be so mind-boggling huge and complex? It's like they took every possible feature that could be somewhat related to words and stuffed it into the app. And yet most users I know, those just writing simple documents, loathe Word. How can this be?

The answer, of course, is complexity. Microsoft, in their obsession with features, tried to make Word do everything a user could possibly want. In the process it grew into an unwieldy beast that's hard to use for simple tasks.

Lately I've been paying attention to a new breed of applications whose focus is, simply, focus. They take one task and make it dead simple. The application is small, lean, and stupidly easy to use. Then they stop.

Boy, I sure hope this is a trend.

Continue reading "The Power of Focused Applications" »

The Perils of Bad C/C++ Schools

Joel Spolsky recently argued against teaching comp-sci courses in Java, saying schools do a great disservice to students and future employers by not teaching C pointers, recursion, and functional programming. I agree on most points, but I must argue that the average school teaching C/C++ isn't doing that great of job, either.

In my day, the Duke CS department taught C++. The data structures course covered what you'd expect, including pointers and recursion. Joel speaks of your program saying "segmentation fault" when you struggle with pointers, but here's the rub: I'm pretty sure most students dink with their program until it stops segfaulting and produces the right output, but they still don't understand pointers.

Continue reading "The Perils of Bad C/C++ Schools" »

Code Snippet: Unit Test Green/Red Bar for ANSI Terminals

If you like writing unit tests but you don't have a fancy "green bar/red bar" unit test window, here's a simple solution you can use in any ANSI terminal window. It looks like this:

Green/red bar screen shot

It's a piece of cake with some ANSI escape codes. Here's the code:

Continue reading "Code Snippet: Unit Test Green/Red Bar for ANSI Terminals" »

Mini-Pattern/Code: Tokenize In Place

Quickly tokenize a string without copying, much like strtok(), but usable in a multi-threaded environment. Commonly used for parsing communications protocols. Only use when you don't need to keep the original string intact.

Continue reading "Mini-Pattern/Code: Tokenize In Place" »

On Unit Testing and Object Coupling

Most software developers have heard about unit testing, where you create test code for all bits of application code. The idea is that if the tests are written well, you can catch most application bugs by just running the unit tests. Most developers agree this is a good idea, but in the end, most developers don't write unit tests.

The most common objection I hear goes something like this: "it's a great idea, but I don't see how my application can be broken down into small chunks for effective unit testing." Ah, and there's the rub: most existing apps are not designed so they can be easily unit tested. But the common mistake is to assume that most apps cannot be designed for easy unit testing. In fact, I'm pretty sure that most can.

The problems with existing code usually revolve around object coupling, where software objects rely on other objects to do their job. What follows is a discussion of how unit testing (and especially test-first practices) affects software design and the relationships of software objects.

Continue reading "On Unit Testing and Object Coupling" »

Mini-Pattern: Interval

Create an easy way to check if a certain amount of time has elapsed, but avoid rollover problems.

Continue reading "Mini-Pattern: Interval" »

Mini-Pattern: Resource User

Next pattern: a great gem buried in the Stroustrup book.

Define a lightweight class for a resource in use, and declare it on the stack. The destructor closes the resource when the instance goes out of scope. This ensures that the resource is always released when no longer needed.

Continue reading "Mini-Pattern: Resource User" »

Mini-Pattern: Error Function

I have a bunch of "mini-patterns" that I've been collecting, small nuts-n-bolts level patterns I've either created myself or found elsewhere over my past 10 years as a software engineer. I'm going to start posting them here in case others find them useful. So, without further ado, first mini-pattern:

Instead of returning an error code directly, use a function that can provide logging or other necessary functionality in addition to returning the error code.

Continue reading "Mini-Pattern: Error Function" »

IPTCInfo 1.9

Version 1.9 of IPTCInfo is now out. Just a bug-fix release.

XML::GXML Perl Module

XML::GXML is a Perl module for transforming XML. It may be put to a variety of tasks; in scope it is similar to XSL, but less ambitious and easier to use (including a less verbose syntax). GXML is an outgrowth of gxml2html, my tool for converting web sites written in XML to HTML output.

These are some of GXML's features:

  • Template substitution for any given element.
  • Templates may be provided by user code or files on disk.
  • Any part of the XML, source or template, may contain variables which will be substituted according to well-defined rules.
  • Variable values may be: things embedded in an enclosing element's start tag, other elements in scope, sub-values of an in-scope element, or provided by user code.
  • Element tags can have variables in them.
  • Special commands allow conditionals and looping, e.g. "if exists," "if equals," and "foreach."
  • User can specify callbacks for start and/or end of given tags.
  • Element tags can be easily remapped to other things.
  • XML syntax can be easily translated into HTML syntax.

Continue reading "XML::GXML Perl Module" »