Code Metrics sure get mixed feelings by developers, especially when combined with thresholds to form checks that might make a CI build fail. Typical examples are:

Line based code coverage  must not fall below 80%.

A method must not be longer than 15 lines of code.

Arguments against such rules state there are cases where such checks limit the freedom of a developer.
During a discussion around these things it occurred to me that the metrics and checks come from a different skill level than the arguments against them.

Let me introduce Shuhari:

Shuhari is a Japanese martial arts concept describing the stages of learning to mastery.

Shu describes the strict adherence to rules as one does when one begins to learn. This is where metrics live. They are strict rules. As a practitioner you just follow the rules without really thinking about them.

Ha describes the bending, changing and breaking of rules, as you might do when you are quite experienced.

Ri finally is described as transcendence, i.e. the rules don't really have a meaning to a master on this level. She just knows what to do.

I think one can easily see how metrics get in the way of a master at the higher levels. Right? But there is an interesting point in the short Wikipedia article for Shuhari:

Shuhari can be considered as concentric circles, with Shu within Ha, and both Shu and Ha within Ri. The fundamental techniques and knowledge do not change.

For me this means: While a master can and will break rules at will, most of the time she won't because the rules align with what is the right thing to do (tm).

So if you think those code metrics are stupid and shouldn't apply to your code, you are welcome to prove to me that you are a Ri level master (I'm certainly not). A first indicator would be that you can follow those rules without them actually being enforced.

But if you are constantly breaking builds due to Checkstyle, PMD and Sonar violations, you are not demonstrating mastership but sloppy working.

Talks

Wan't to meet me in person to tell me how stupid I am? You can find me at the following events: