Metrics & Object-oriented programming

2020-07-17 16:02发布

I would like to know if somebody often uses metrics to validate its code/design. As example, I think I will use:

  • number of lines per method (< 20)
  • number of variables per method (< 7)
  • number of paremeters per method (< 8)
  • number of methods per class (< 20)
  • number of field per class (< 20)
  • inheritance tree depth (< 6).
  • Lack of Cohesion in Methods

Most of these metrics are very simple.

What is your policy about this kind of mesure ? Do you use a tool to check their (e.g. NDepend) ?

标签: oop metrics
7条回答
手持菜刀,她持情操
2楼-- · 2020-07-17 16:46

OO Metrics are a bit of a pet project for me (It was the subject of my master thesis). So yes I'm using these and I use a tool of my own.

For years the book "Object Oriented Software Metrics" by Mark Lorenz was the best resource for OO metrics. But recently I have seen more resources.

Unfortunately I have other deadlines so no time to work on the tool. But eventually I will be adding new metrics (and new language constructs).

Update We are using the tool now to detect possible problems in the source. Several metrics we added (not all pure OO):

  • use of assert
  • use of magic constants
  • use of comments, in relation to the compelxity of methods
  • statement nesting level
  • class dependency
  • number of public fields in a class
  • relative number of overridden methods
  • use of goto statements

There are still more. We keep the ones that give a good image of the pain spots in the code. So we have direct feedback if these are corrected.

查看更多
登录 后发表回答