This is simply my own interpretation. I deem my code clean when:
- The physical layout of the program is consistent (internally and with my other programs). Module uses (including strict and warnings) are at the top, followed by the program flow, followed by subroutines (declarations excluded), and then the end of the program. Below is POD as needed. My indentation is consistent throughout, my brace style is consistent, etc. There shouldn't be a chunk of code that looks out of place.
- All variables have the proper scope, and are declared when it is most fitting to do so.
- No code is obfuscated, and any code that is less than intuitive is commented clearly.
- The code is structured in paragraphs. I try to keep the number of consecutive non-empty lines to a sensible number. This way, comments can act as "headers" to my paragraphs of code.
Argument checking is done in most cases, and if I'm writing a module, I'll always use
Carp's functions to raise errors.
I've probably left out some concepts, but it comes down to this: would I feel confident showing my code to my fellow developers (or peers in general), and would I expect them to understand the operation of my code without me intervening?