wissel.net

Usability - Productivity - Business - The web - Singapore & Twins

By Date: January 2019

Avoid the "Clean Code Shock" with PMD

Hero image for Avoid the "Clean Code Shock" with PMD

Your new year resolution includes "Write clean Apex code". So you run PMD with a full ruleset and get shocked by the number of violations. You drop the resolution in a blink.

Don't boil the Ocean

Even a journey of a thousand miles starts with a single step, so let's break down the task into manageable chunks to divide and rule.
There are 2 dimensions you can use: Type of code and priority levels. Using them you can turn your Clean Code journey into manageable stages.

Code Types

  • Legacy code: all code that doesn't fall in any of the two other categories
  • Changed code: code that needs change due to business requirements
  • New code: new code written for new or changed functionality (applies to copy & paste too)

Priority Levels

  • 1 = security and performance, will fail build
  • 2 = bad code, will fail build
  • 3 & 4 = hard to maintain code, will generate warning
  • 5 = ugly code, will generate hint

PMD rules for code types should have different priorities. A different number of tests will fail a build:

  • 11 for legacy code (all around performance and security)
  • 33 for changed code
  • 44 for new code

This will require to run PMD with different rulesets on subsets of your code base


Read more

Posted by on 02 January 2019 | Comments (0) | categories: Apex PMD Salesforce