Most developers like to write clean code. So, why is so much code in the world messy? Although there are many opinions about this, there are two contributing causes that very most everyone will agree on.
One of the reasons is that there is rarely enough time to write code as cleanly as we would like. Even when code starts clean, the continual refactoring from changing requirements, shifting dependencies, and the inevitable bug fixes (often a result of the first two factors) leads to messy code just as surely as short deadlines and long hours make an organized person's desk become littered with piles of unfiled papers and unfinished notes.
The other reason that is generally agreed on for code in the real world not being as clean as it starts out in our minds is because not everyone generally agrees with what clean code should look like. Some people are more certain that their version is cleaner than another, and there are people who hold different opinions with equal conviction. For example, in which row does the opening brace of a method belong? This is an example where I'm fairly certain I am not the only person who has had endless email threads and inconclusive meetings. The one, final answer will not be decided in our lifetime.
Even though the coding standards of an enterprise or project team may begin as a democratic process, they will not be useful as a benchmark until their definition evolves to a benevolent dictatorship (remember, I am discussing business, not government here). Once the standards are defined, a third reason for not meeting them comes into play; there are usually more rules than most folks can memorize, or remember when the time pressure is on or when the rules of one project differ from those of another. For these causes of messy code, I have found PMD to be the best solution based on its flexibility and ease of use. The letters themselves do not really stand for anything. The creator(s) just thought they sounded good together. The PMD home page supplies several "backronyms" to explain it.
Read the Rest of this Article at Developer.com