Self-Documenting Code

It sounds like a good idea, doesn’t it? But what is self-documenting code? This program is self-documenting:

10 PRINT "I am very small and very pointless"
20 GOTO 10

It’s not anything to be proud of, though. A more complicated, more useful self-documenting program requires a great deal of skill. Computer programs tend to be much harder to read than they are to write. Anyone who has used Perl will understand this; it has been described as the ultimate write-once language. Indeed, old Perl code can be truly unfathomable, but you can write opaque code in any language, and it doesn’t take much effort.

The only document that describes your code completely and correctly is the code itself. That doesn’t automatically mean it’s the ...

Get Code Craft now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.