Program As If Your Maintenance Programmer Were Not a Barely-Competent Monkey

by chromatic

Here's a provocative thought from Mark-Jason Dominus on a rainy Friday afternoon:

Programming cannot be run on the convoy system, with the program code written to address the most ignorant, uneducated programmer. I think you have to assume that the next maintenance programmer will be competent.... If an incompetent programmer has trouble understanding your code, that is not your fault; it is their fault for being incompetent. You do not have to take special steps to make your code understandable even by incompetents, and you certainly should not do so at the expense of making it harder for competent programmers to read and understand, no, not to the tiniest degree.

— Mark-Jason Dominus, Creeping featurism and the ratchet effect

Please note that I don't believe that any one particular programming language can solve this problem; see Does Your Programming Language Have Magic Powers? This is a people problem.


matthew sporleder
2007-11-17 09:15:17
Do you have some better examples? The source of this quote gives:

next if ($file =~ /^\./);
next if !($file =~ (/[0-9]/));
next if !($file =~ (/txt/));

And although I agree that the (parentheses) around /regex/ are detrimental to readability, I fail to see how they're bad for an 'if'. (even if it doesn't have a { block } afterwards.)

Mark Dominus
2007-11-19 17:41:13
That was the post that inspired Jonathan Rentzsch to say that he wished he could hire me just so that he could fire me.

I emailed him asking about his company's severance benefits but he never replied.

Martin Kr├╝ger
2007-11-20 04:38:51
I agree. The first issue on programming is, that the program works, not that it is understandable by others. Which does not mean, that it shouldn't be understood by others.
J.T. Wenting
2007-11-22 05:23:39
Write code you'd not mind to maintain yourself. If that means writing code for monkeys, so be it.
If you think you can tell what that 3 line regular expression does in the middle of that method full of single character variable names and calls to methods with names that make no sense and have parameter lists that go on for ages, then good luck to you (and I deplore your replacement).
2007-11-22 10:48:11
@J.T., I agree. There's no excuse for writing unmaintainable code, but deliberately avoiding libraries and well-known language idioms and advanced features of a language because you fear your successor might not know how to program is silly.

I've seen people read from and write to files because they didn't understand how to use arrays. I've also seen people write code in unnatural ways because "some of the other programmers in our team don't understand map". It seems to me that there's a better solution to that than writing baby code that's not the most natural (and especially not the most maintainable) way to write the code.