Live data from Hacker News

Measuring Software Complexity: What Metrics to Use?

thevaluable.dev

11–20 of 87 posts

Re: Measuring Software Complexity: What Metrics to Use?

#11
I always liked the notions of coupling and cohesion because they are simple to understand and you can see at the glance of an eye if a particular bit of code would have good metrics for those, without actually bothering with the metrics. E.g. long list of parameters or imports == high coupling, large number of fuctions in a module == low cohesion. Specifying exactly how much isn't that useful. It's easier to think in terms of "relative to the rest of the code". Debating what is too high or too low even less so. But if you are struggling with working with a particular bit of code, being able to identify why it is hard to deal with is useful; especially if you know how to fix it.

But mostly metrics should not be telling you things you can't already know just looking at the code; if it looks complicated, it probably is. Metrics only become useful when you need to tell without looking. Sometimes that's useful.

Re: Measuring Software Complexity: What Metrics to Use?

#12
The Einstein quote is that "something should be a simple as needed but no simpler", but how to be pin down "required" in an objective / quantifiable way?

Somehow it is more important to measure "gratuitous" complexity, redundant complexity that is not justified by present or plausible future requirements...

The problem is that the code itself does not capture requirements, so code analysis can give you absolute indicators but never an "efficiency" measure (how efficient and justified the measured complexity)

Re: Measuring Software Complexity: What Metrics to Use?

#14
post #7

Ugh, no. I’ve worked in a codebase where CI would reject changes that had too much ‘code complexity’. You’d constantly have to find clever ways to split up your code, when doing so did not make sense, to appease the complexity checker. Oh yeah, and if you ever make a one-liner change, you might end up being forced to do a full refactor because that one line pushed the complexity threshold over the edge. The results:…

I'm sorry about your experience, but from what it seems, your problem was in your team. Any measure can be turned into a bad policy, code complexity is a red herring here.

Re: Measuring Software Complexity: What Metrics to Use?

#15

No mention of function points.

I agree. Certains functions are way more complicated and hard to show value for than others, which is really hard to comprehend for some managers.

Functionalities like undo/redo take a lot of planning, coordination and integration efforts than others like a simple export function, but good luck selling that to any marketing or product owner for xx manndays.

I still think that this subject is way too specific to be generalized like this, but general thumb of rules still apply like good estimation and technical planning.

Re: Measuring Software Complexity: What Metrics to Use?

#16
post #7

Ugh, no. I’ve worked in a codebase where CI would reject changes that had too much ‘code complexity’. You’d constantly have to find clever ways to split up your code, when doing so did not make sense, to appease the complexity checker. Oh yeah, and if you ever make a one-liner change, you might end up being forced to do a full refactor because that one line pushed the complexity threshold over the edge. The results:…

Couldnt yout just raise the threshold by tweaking the config with your PR instead?

I do this all the time with other automated checkers (linters, etc.). I don't see why this should be different. If another human agrees it shouldnt be a problem.

Re: Measuring Software Complexity: What Metrics to Use?

#18

I didn't see anything on Function Point counts in the article. No advocating it per se but it was, at one time, considered one of the more useful ways to evaluate codebase complexity.

FP analysis is a measure for the "amount of functionality" not complexity. Maybe in relation to, e.g., the number of statements (statements/FP) it could make sense.

Re: Measuring Software Complexity: What Metrics to Use?

#19

The Einstein quote is that "something should be a simple as needed but no simpler", but how to be pin down "required" in an objective / quantifiable way? Somehow it is more important to measure "gratuitous" complexity, redundant complexity that is not justified by present or plausible future requirements... The problem is that the code itself does not capture requirements, so code analysis can give you absolute indic…

Isn't the general goal rather to avoid/eliminate overly complex cruft (that every programmer should be able to recognize) than to find the maximally simple solution to a problem?

Re: Measuring Software Complexity: What Metrics to Use?

#20
post #7

Ugh, no. I’ve worked in a codebase where CI would reject changes that had too much ‘code complexity’. You’d constantly have to find clever ways to split up your code, when doing so did not make sense, to appease the complexity checker. Oh yeah, and if you ever make a one-liner change, you might end up being forced to do a full refactor because that one line pushed the complexity threshold over the edge. The results:…

Use the tool, don't become its slave.
Post reply on HN