What code metric(s) convince you that provided cod

2019-01-21 04:03发布

Code lines per file, methods per class, cyclomatic complexity and so on. Developers resist and workaround most if not all of them! There is a good Joel article on it (no time to find it now).

What code metric(s) you recommend for use to automatically identify "crappy code"?

What can convince most (you can't convince all of us to some crappy metric! :O) ) of developers that this code is "crap".

Only metrics that can be automatically measured counts!

27条回答
聊天终结者
2楼-- · 2019-01-21 04:41

Unfortunately there is not a metric that I know of. Something to keep in mind is no matter what you choose the programmers will game the system to make their code look good. I have seen that everywhere any kind of "automatic" metric is put into place.

查看更多
SAY GOODBYE
3楼-- · 2019-01-21 04:41

Sometimes, you just know it when you see it. For example, this morning I saw:

void mdLicense::SetWindows(bool Option) {
  _windows = (Option ? true: false);
}

I just had to ask myself 'why would anyone ever do this?'.

查看更多
一纸荒年 Trace。
4楼-- · 2019-01-21 04:43

Well, there are various different ways you could use to point out whether or not a code is a good code. Following are some of those:

  1. Cohesiveness: Well, the block of code, whether class or a method, if found to be serving multiple functionality, then the code can be found to be lower in cohesiveness. The code lower in cohesiveness can be termed as low in re-usability. This can further be termed as code lower in maintainability.

    1. Code complexity: One can use McCabe cyclomatic complexity (no. of decision points) to determine the code complexity. The code complexity being high can be used to represent code with less usability (difficult to read & understand).

    2. Documentation: Code with not enough document can also attribute to low software quality from the perspective of usability of the code.

Check out following page to read about checklist for code review.

查看更多
Root(大扎)
5楼-- · 2019-01-21 04:47

number of global variables.

查看更多
霸刀☆藐视天下
6楼-- · 2019-01-21 04:48

Number of worthless comments to meaningful comments:

'Set i to 1'
Dim i as Integer = 1
查看更多
Melony?
7楼-- · 2019-01-21 04:48
  • Watch out for ratio of Pattern classes vs. standard classes. A high ratio would indicate Patternitis
  • Check for magic numbers not defined as constants
  • Use a pattern matching utility to detect potentially duplicated code
查看更多
登录 后发表回答