A lot of the answers say that a good programmer should know to throw his principles over board when faced with an impossible deadline. I disagree. I think, a good programmer is one that can perform under pressure. A quarterback who can only throw when he is not attacked is not a good a quarterback. A musician who can only play when noone's listening is not a good musician. A soldier who loses his head as soon as someone shoots at him is not a good soldier. And what would have happened to the passengers of US Airways 1549 if Captain Sullenberger had thrown all good principles of airmanship over board, just because he was in a stressful situation?
And a programmer that resorts to spaghetti code when the deadline looms is not a good programmer.
In one of the answers, someone wrote that when the deadline nears one should take the path of least resistance. So, we have to make sure that following XP practices, doing TDD, following the SOLID principles, writing clean code and all that goes along with it, become the path of least resistance.
The question is: how do we do that? Well, how do these other guys, athletes, soldiers, musicians, pilots do that? The answer is: practice and training. Soldiers spend 40 hours a week training for stress events that they hope will never happen. Before the successful ditching of Flight 1549, it was widely believed to be impossible to safely waterland a large commercial passenger aircraft, and yet, simulator training for this event is mandatory. Programmers OTOH usually do not train at all, even though they know that they will have to code under a deadline.
One idea that for example Micah Martin has tossed around, comes from martial arts: Kata. Kata are a ritualized performance of a strictly defined sequence of strictly defined, usually pretty basic, moves. These moves are usually not technically difficult, nor physically demanding. Kata are also very short, typically just a few minutes. What's most important about a Kata is not just that you perform the prescribed moves, but how you do it. Another important aspect is that Kata are actually performed, together with others, in front of an audience, your fellow students, your master and sometimes judges.
A Kata should be a simple coding project that takes no longer than 10 minutes to complete. You should do this over and over again, practice daily, and more importantly perform regularly in front of your co-workers, your local usergroup, or at a conference. And you should ask them to judge you.
If you want to see what something like that looks like, Micah Martin has publicly performed his Kata a couple of times, for example during his talk at RubyConf 2008.
Ask yourself: when was the last time you completely threw higher-level control flow constructs out the window and used only GOTO
? We are so intimately familiar with for
, foreach
, while
, until
, repeat
, loop
, map
, reduce
, filter
and friends that we would never even dream of GOTO
. And I believe that with enough practice, the same can be achieved for testing, factoring, DDD, TDD, SOLID, and everything else.