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条回答
Anthone
2楼-- · 2019-01-21 04:49

I am surprised no one has mentioned crap4j.

查看更多
Luminary・发光体
3楼-- · 2019-01-21 04:49

Code coverage has some value, but otherwise I tend to rely more on code profiling to tell if the code is crappy.

查看更多
疯言疯语
4楼-- · 2019-01-21 04:50

At first sight: cargo cult application of code idioms.

As soon as I have a closer look: obvious bugs and misconceptions by the programmer.

查看更多
你好瞎i
5楼-- · 2019-01-21 04:52

Lines of comments / Lines of code

value > 1 -> bad (too many comments)

value < 0.1 -> bad (not enough comments)

Adjust numeric values according to your own experience ;-)

查看更多
兄弟一词,经得起流年.
6楼-- · 2019-01-21 04:53

A lot of conversions to and from strings. Generally it's a sign that the developer isn't clear about what's going on and is merely trying random things until something works. For example, I've often seen code like this:

   object num = GetABoxedInt();
//   long myLong = (long) num;   // throws exception
   long myLong = Int64.Parse(num.ToString());

when what they really wanted was:

   long myLong = (long)(int)num;
查看更多
ゆ 、 Hurt°
7楼-- · 2019-01-21 04:54

My personal favourite warning flag: comment free code. Usually means the coder hasn't stopped to think about it; plus it automatically makes it hard to understand, so ups the crappy ratio.

查看更多
登录 后发表回答