Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Netbeans 7.4 introduces "10 lines max" per method rule. Where does this rule come from? [closed]

NetBeans 7.4 beta is currently available for public download, and it introduces a weird warning rule by default:

Method length is 16 lines (10 allowed)

My question is: Is this an accepted code convention rule, that can be proven somehow, somewhere ? NetBeans support/devs say it's not a bug, but don't give a statement why they only allow 10 lines, and where exactly this rule has its origin.

like image 725
Sliq Avatar asked Aug 09 '13 12:08

Sliq


2 Answers

The "10 lines rule" has to do with enforcing test-driven development. The theory is that any method that has more than ten lines can be better broken down into units that are testable. it holds up in theory, but in practice a warning like this is more annoying than helpful.

like image 34
Matt Avatar answered Oct 24 '22 19:10

Matt


You can change the maximum method/function length warning behavior in NetBeans options (it's under Tools->Options->Editor, in the Hints tab, under "Too Many Lines" section in the checkboxes list).

There you can set the maximum number of lines, how you would like to be warned, etc.

I believe that the rule was introduced by NetBeans developers because when working in teams, the automated tools that QAs use to "inspect" code flag long method declarations/functions bodies. Unfortunately, the use of automated tools by "code analysts" is on the rise, whilst their understanding of the reasons behind that are still limited. I do not say that your functions should be hundreds of lines long - that's just plain wrong, but a hard-coded number as a coding law - come on!

like image 149
Milen Avatar answered Oct 24 '22 17:10

Milen