Coding Horror

programming and human factors

What Can You Build in 600 Lines of Code?

Joseph Cooney reminds us that, in January 2005, 37signals went live with a product they built in 579 lines of code:

You read that right, not 60,000 or 600,000 but instead a commercial project written in less than 600 lines of Ruby code. When I first saw this number I was incredulous -- I've written stored procedures that are longer than that. My current project has more lines of configuration than that. I've even written console apps in notepad, and compiled from the command line with more lines than that, because I thought they were so small they didn't need a whole .sln and .proj file, and yet here is 37signals going live with a product that is just 579 lines of Ruby.

As noted in the Rails blog, the original product launch was covered on Ruby language creator Matz' blog in his native Japanese. Surprisingly, the relevant facts are still readable:

matz makes notes of ta-da list and Rails

Of course, a simple lines of code number isn't the entire story-- they actually built the entire Rails framework first to support building small apps like ta-da list. None of the required Rails framework code, nor any of the the necessary stylesheets, JavaScript, HTML, and so forth, are included in that number. Still, I agree with Joseph: it's an impressive achievement, and it can lead to some interesting thought experiments:

I have a few interesting product ideas from time to time. What is the absolute minimum amount of code I could write that would make those ideas work? If I'm prepared to operate within the constraints of the platform (whatever that is) how much effort would that save me? How many more "interesting ideas" could I turn into working products if I was prepared to follow these constraints? How many more cool/useful things could you build if you promised yourself that each one would only be 600 lines of code?

What can you build in 600 lines of code? Think of it as an exercise in minimalism. Does your preferred language or environment allow you the freedom to create something interesting and useful with that constraint in place?

Discussion

Getting the Interview Phone Screen Right

The job market for software developers is hot. This is great news for programmers, but it makes the interview process challenging for potential employers. A reader recently wrote me expressing some concern about the interview process:

You mention Vertigo requiring a code sample, then a phone screening, then a hands-on test in the face-to-face. We have a very similar process, but somehow a large percentage of the candidates who make it to the hands-on test are very poor and should have been eliminated at step 1 or 2. The signal to noise ratio is terrible. It costs a great deal to spend so much time doing face-to-face interviews with people who often should not be developers in the first place. I am curious how much light you might be able to shed on the specifics of your requirements on candidates. What part of the process is the most effective in separating the cream, how and why?

It is very expensive to get the phone screen wrong-- a giant waste of time for everyone involved.

rotary phone

The best phone screen article you'll ever find is Steve Yegge's Five Essential Phone-Screen Questions, another gift to us from Steve's stint at Amazon.

Steve starts by noting two critical mistakes that phone screeners should do their best to avoid:

  1. Don't let the candidate drive the interview. The interviewer should do most of the talking, guiding the conversation along until they're satisfied the candidate knows the answers to the questions (or has given up).
  2. Watch out for one-trick ponies. Candidates who only know one particular language or programming environment, and protest complete ignorance of everything else, are a giant red warning flag.

The point of the phone screen is not for the candidate to drone on about what they've done. The interviewer should push them out of their comfort zone a bit and ask them related questions about things they haven't seen or done before. Ideally, you want to know how this person will react when they face something new, such as your codebase.

In an effort to make life simpler for phone screeners, I've put together this list of Five Essential Questions that you need to ask during an SDE screen. They won't guarantee that your candidate will be great, but they will help eliminate a huge number of candidates who are slipping through our process today.

1) Coding. The candidate has to write some simple code, with correct syntax, in C, C++, or Java.

2) OO design. The candidate has to define basic OO concepts, and come up with classes to model a simple problem.

3) Scripting and regexes. The candidate has to describe how to find the phone numbers in 50,000 HTML pages.

4) Data structures. The candidate has to demonstrate basic knowledge of the most common data structures.

5) Bits and bytes. The candidate has to answer simple questions about bits, bytes, and binary numbers.

Please understand: what I'm looking for here is a total vacuum in one of these areas. It's OK if they struggle a little and then figure it out. It's OK if they need some minor hints or prompting. I don't mind if they're rusty or slow. What you're looking for is candidates who are utterly clueless, or horribly confused, about the area in question.

Of course, you'll want to modify this process to reflect the realities at your shop-- so I encourage you to read the entire article. But Steve does provide some examples to get you started:

Coding

Write a function to reverse a string.
Write function to compute Nth fibonacci number.
Print out the grade-school multiplication table up to 12x12.
Write a function that sums up integers from a text file, one int per line.
Write function to print the odd numbers from 1 to 99.
Find the largest int value in an int array.
Format an RGB value (three 1-byte numbers) as a 6-digit hexadecimal string.

Good candidates for the coding problem are verifiably simple, with basic loops or recursion and perhaps a little formatted output or file I/O. All we want to know is whether they really do know how to program or not. Steve's article predates it, but I'd be remiss if I didn't mention Why Can't Programmers.. Program? here. The FizzBuzz problem is quite similar, and it's shocking how often interviewees can't do it. It's a bit hard to comprehend, like a potential truck driver somehow not being able to find the gas pedal or shift gears.

Object-Oriented Programming

Design a deck of cards that can be used for different card game applications.
Model the Animal kingdom as a class system, for use in a Virtual Zoo program.
Create a class design to represent a filesystem.
Design an OO representation to model HTML.

We're not saying anything about the pros and cons of OO design here, nor are we asking for a comprehensive, low-level OO design. These questions are here to determine whether candidates are familiar with the basic principles of OO, and more importantly, whether the candidate can produce a reasonable-sounding OO solution. We're looking for understanding of the basic principles, as described in the Monopoly Interview.

Scripting and Regular Expressions

Last year my team had to remove all the phone numbers from 50,000 Amazon web page templates, since many of the numbers were no longer in service, and we also wanted to route all customer contacts through a single page.

Let's say you're on my team, and we have to identify the pages having probable U.S. phone numbers in them. To simplify the problem slightly, assume we have 50,000 HTML files in a Unix directory tree, under a directory called "/website". We have 2 days to get a list of file paths to the editorial staff. You need to give me a list of the .html files in this directory tree that appear to contain phone numbers in the following two formats: (xxx) xxx-xxxx and xxx-xxx-xxxx.

How would you solve this problem? Keep in mind our team is on a short (2-day) timeline.

This is an interesting one. Steve says 25% to 35% of all software development engineer candidates cannot solve this problem at all-- even with lots of hints and given the entire interview hour. What we're looking for is a general reluctance to reinvent the wheel, and some familiarity with scripting languages and regular expressions. To me, this question indicates whether a developer will spend days doing programming work that he or she could have neatly avoided with, perhaps, a quick web search and some existing code that's already out there.

Data Structures

What are some really common data structures, e.g. in java.util?
When would you use a linked list vs. a vector?
Can you implement a Map with a tree? What about with a list?
How do you print out the nodes of a tree in level-order (i.e. first level, then 2nd level, then 3rd level, etc.)
What's the worst-case insertion performance of a hashtable? Of a binary tree?
What are some options for implementing a priority queue?

A candidate should be able to demonstrate a basic understanding of the most common data structures. More specifically, the big ones like arrays, vectors, linked lists, hashtables, trees, and graphs. They should also know the fundamentals of "big-O" algorithmic complexity: constant, logarithmic, linear, polynomial, exponential, and factorial. If they can't, that's a huge warning flag.

Bits and Bytes

Tell me how to test whether the high-order bit is set in a byte.
Write a function to count all the bits in an int value; e.g. the function with the signature int countBits(int x)
Describe a function that takes an int value, and returns true if the bit pattern of that int value is the same if you reverse it (i.e. it's a palindrome); i.e. boolean isPalindrome(int x)

As Steve says, "Computers don't have ten fingers, they have one. So people need to know this stuff." You shouldn't be treated to an uncomfortable silence after asking a candidate what 2^16 is; it's a special number. They should know it. Similarly, they should know the fundamentals of AND, OR, NOT and XOR-- and how a bitwise AND differs from a logical AND. You might even ask about signed vs. unsigned, and why bit-shifting operations might be important. They should be able to explain why the old programmer's joke, "why do programmers think Oct 31 and Dec 25 are the same day?" is funny.

Performing a thorough, detailed phone screen is a lot of work. But it's worth it. Every candidate eliminated through the phone screen saves at least 8 man-hours of time that would have been wasted by everyone in a hands-on test. Each time an unqualified candidate makes it to the hands-on test, you should be asking yourself-- how could we have eliminated this candidate in the phone screen?

Discussion

Reinventing the Clipboard

Over time, I've become something of a desktop mimimalist. Sure, I'll change a few settings to my liking, but I no longer spend a lot of time customizing my desktop configuration. I've learned that if the defaults aren't reasonably close to correct out of the box, then the software is probably doomed anyway. For most users the default settings are the only settings.

One of the things I always have to change, much to my chagrin, is the default clipboard behavior. I originally wrote about this in 2005:

In this era of 3 GHz processors, 1 GB memory, and 500 GB hard drives, why is the Windows clipboard only capable of holding a single item? Sure, you have fancy multi-level undo and redo in applications like Microsoft Word and Visual Studio. But not the clipboard. It holds exactly one item. Copy another item to the clipboard and your previous clipboard item is irrevocably lost.

The only improvement since then, sadly, is in the PC specifications. Three years later, we're stuck with the same old single-item clipboard model. The clipboard isn't some obscure operating system feature, either. People use it all the time. There's actually hard data to back this up, at least for Word 2003:

Top 5 Most-Used Commands in Microsoft Word 2003
  1. Paste
  2. Save
  3. Copy
  4. Undo
  5. Bold

Together, these five commands account for around 32% of the total command use in Word 2003. Paste itself accounts for more than 11% of all commands used, and has more than twice as much usage as the #2 entry on the list, Save.

Granted, we're talking about a word processing program here, but we live in a copypasta culture. I find that even when I'm not writing, per se, I rely on my clipboard throughout the day. The clipboard is so important that Walter Mossberg specifically mentioned it as a negative in his iPhone review:

There's also no way to cut, copy, or paste text.

This is on a phone, mind you. I'm totally with Walt on this one; it applies to all smartphones. I was surprised how quickly I ran into situations where I wanted to copy and paste something on my Windows Mobile phone, but I couldn't figure out how to. It's not a crippling limitation, but it does illustrate how fundamental the clipboard is, even for the smallest of computers.

It always seemed strange to me that applications had to implement their own oddball per-app clipboard queues to spackle over deficiencies in the operating system's braindead "I can only remember one thing at a time" clipboard implementation. We've long since left the days of applications writing their own quirky little file open dialog behind, but it's somehow OK to implement your own wacky clipboard behaviors in Visual Studio, or Office?

If, like me, you'd prefer operating system level improvements in the clipboard, there are quite a few options out there. I've been quite happy with ClipX. After installing this lightweight little app, instead of pressing

Ctrl + V

to paste a single item, you can opt to press

Ctrl + Shift + V

whereupon you're presented with a menu of recent clipboard items, in a nice visual menu browser format:

ClipX screenshot

Your clipboard history is dynamically saved to disk and will survive a reboot, so you can begin to rely on your clipboard as a sort of quick and dirty digital scrapbook. Isn't that how it should have been all along?

I've become terribly reliant on this improved clipboard behavior, so I always install ClipX on any machine I'm working on. It has some additional default clipboard functions that I've also found quite useful:

Ctrl + Shift + G

perform a Google search using the contents of the clipboard.

Ctrl + Shift + N

open a browser and navigate to the address in the clipboard.

It doesn't matter whether you specifically choose ClipX. It's these three key improvements in the operating system clipboard that I think are important:

  1. history
  2. persistence
  3. visual browser

It's a mystery to me why none of the major operating systems have bothered improving the clipboard. It seems entirely possible to add these enhancements without breaking the simple clipboard paradigms that have been around since the days of Xerox PARC.

Discussion

The Sesame Street Presentation Rule

After being on both the giving and receiving end of plenty of presentations, I now realize there's one golden rule which applies to all of them:

Entertain your audience.

Every slide of your presentation should serve this fundamental vision statement. Is it entertaining? I don't mean each slide has to contain a wacky joke of some kind. Every slide should provoke a reaction from the audience -- be it controversial, unexpected, amusing, or a meditative Zen koan. Prod your audience. Do this not only to keep them awake, but to engage their brains. Deliver a series of short, sharp shocks that jolt your audience into a heightened state of engagement.

Once your audience has engaged with your presentation, that's when you trick them into learning. The very best presentations entertain and educate-- the common portmanteau is edutainment. The archetypal example of edutainment is Sesame Street.

Sesame Street characters in a group photo

Sesame Street is the second longest running children's show in the world, racking up 4,160 episodes over 38 seasons so far. They must be doing something right.

The show's format called for the humans to be intermixed with the segments of animation, live-action shorts and Muppets. These segments were created to be like commercials-- quick, catchy and memorable-- and made the learning experience much more like fun. The format became a model for what is known today as edutainment-based programming.

CTW aired the program for test groups to determine if the revolutionary new format was likely to succeed. Results showed that test watchers were entranced when the ad-like segments aired, especially those with the jovial puppets, but were remarkably less interested in the street scenes. Psychologists warned CTW against a mixture of fantasy and reality elements, but producers soon decided to mix the elements. A simple dose of cartoon-like characters lets the humans deliver messages without causing viewers to lose interest.

You might think it's patronizing to lift techniques from a television show aimed at preschoolers, but I find that people of all ages need to be entertained to fully engage with what whatever it is you're presenting. That's why your primary goal for any presentation is to entertain. If the audience doesn't walk out of your presentation thinking "gee, that was fun!", then I can practically guarantee they'll remember little about you or your talk. There's nothing more stultifying than walking out of yet another interminable, droning presentation to realize that all you have to show for it is another hour of your life ticked away. If you design to entertain first and teach second, even if your presentation bombs, at least the audience will get some fleeting entertainment out of the time they invested in you.

So the next time you're putting a presentation together, remember the Sesame Street Presentation Rule -- don't forget to add the muppets!

Discussion

See You at CUSEC 2008

I have the distinct honor of speaking at this year's CUSEC, which runs from today until Saturday.

CUSEC 2008 logo

So what, exactly, is CUSEC?

CUSEC is the Canadian University Software Engineering Conference, an annual conference about the most interesting topics in software engineering organized for and by students from universities across Canada. What makes CUSEC unique is that it is the only software specific conference that targets students. This means that the presentations you'll see at CUSEC will be about things that matter to you, not just things that matter to professional developers. That doesn't mean that the speakers we get are nobodies, either. Past speakers include David Lorge Parnas, Kathy Sierra, Ralph Johnson, Kent Beck, Alistair Cockburn, Dave Thomas, and many more.

They weren't kidding about the impressive speaker list. This year's keynote speakers are:

It's hard to shake the feeling that one of these things is not like the others, but I suppose the conference organizers had their reasons for inviting me, however crazy those reasons may seem to me.To provide a sense of history, the CUSEC keynote speakers from 2007:

And the CUSEC keynote speakers for 2006.

I think you get the idea, so there's no need to list the 2005 speakers. It's an honor to be among such distinguished speakers. How distinguished? Many of these folks have their own Wikipedia entries! I had the opportunity to meet Tim Bray today, for example. Since 2004, CUSEC has grown into the premier conference by computer science students, for computer science students-- across the whole of Canada. It's too bad there isn't an equivalent student-run conference for American computer science students.

This is also my first trip to Canada. After many years of wanting to visit our northern neighbors, I've finally made it. I have to agree with William Gibson; as he wrote in his book Spook Country, Canadian cities look the way American cities do on television. I'm enjoying Montreal and the Canadian perspective on life tremendously. It's refreshing, although I am not sure I needed the televised Capital One Grand Slam of Curling.

I wasn't able to find any video archives of previous CUSEC keynotes, but I was told by Edward Ocampo-Gooding, our keynote host, that they're capturing hi-def video of this year's keynotes. Assuming my talk isn't a total disaster, I'll update this post with a link to my keynote when it is available.

Update: 1/11/09 Video of my CUSEC keynote is now available.

Jeff Atwood - Is Writing More Important Than Programming? from CUSEC on Vimeo.

Update: 1/23/08 My CUSEC 2008 keynote slides, "Is Writing More Important Than Programming?", are available for local download (ppt, 3mb). Discussion