Are software metrics in both directions

I just started working in a large company. in a recent internal audit, measuring indicators such as Cyclomatic complex and file sizes, it turned out that several modules, including those belonging to my team, have a very high index. so last week we all focused on lowering these indices for our code. deleting decision points and breaking files.

I may be missing something new, but how will this improve our software? . I know that software metrics can measure how good your code is, but does the dose work differently around? Will our code improve only because, for example, we create a file of 10,000 lines in 4 files with 2,500 lines?

+6
code-metrics
source share
7 answers

The goal of indicators is to strengthen control over your project. They are not an end in themselves, but can help improve overall quality and / or identify disharmonies in design. Cyclomatic complexity is just one of them.

Test coverage is different. Nevertheless, it is well known that you can get high testing coverage and still have a poor test suite, or vice versa - an excellent test suite in which one piece of code is concentrated. The same thing happens for cyclic complexity. Consider the context of each metric and whether there is something to improve.

You should try to avoid random complexity , but if the processing is of significant complexity , the code will be more complicated anyway. Try writing mainteanble code with a fair balance between the number of methods and their size.

An excellent book that you can pay attention to: Object-oriented indicators in practice .

+6
source share

It depends on how you define "better." Smaller files and less cyclical complexity usually simplify maintenance. Of course, the code itself may still be erroneous, and unit tests and other testing methods will help with this. This is just part of providing more convenient code.

+5
source share

Code is easier to understand and manage in smaller pieces.

It is recommended to group related bits of code in their own functional areas to improve readability and cohesion.

Having a whole large program in one file will make your project very difficult to debug, expand and maintain. I think this is very obvious.

A specific metric is really only an empirical rule, and it cannot be adhered to religiously, but this may mean that something is not as good as it could be.

Whether the previous working code should be affected and processed is something that needs to be evaluated. If you decide to do this, first consider writing tests first, so that you quickly find out if your changes violated any required behavior.

+2
source share

Has one of your own projects ever opened in a few months? The larger and more complex the single components, the more a person asks himself which genius wrote this code and why the hell he wrote it that way. And there is never too much or even enough documentation. Therefore, if the components themselves are less complex and smaller, it is easier to understand "em

0
source share

This is a bit subjective. The idea of ​​assigning an index of maximum complexity cyclicity is to improve maintainability and readability of the code.

As an example, in the perspective of unit testing, it is really convenient to have smaller “units”. And avoiding long codes will help the reader understand the code. You cannot guarantee that the original developer will work on the code forever, therefore, in the future, it is fair for the company to assign criteria such that the code is "simple"

It is easy to write code that a computer can execute. It’s more difficult to write code that a person can understand.

0
source share

How will this improve our software?

Excerpt from the article Fighting the complexity associated with the .NET Developer Tool NDepend . NDepend helps the team manage a large and complex code base. The idea is that code metrics are good and reduce the complex complexity of code implementation:


During my interview with Scott Hanselman's Code Metric on Software Metrics, Scott had a particularly important point.

Basically, although I explained that long and complex methods kill quality and should be divided into smaller methods, Scott asked me:

look at this big too complicated method, and I break it down into smaller methods, the complexity of the business problem still exists, looking at my application, I can say that this is no longer a difficult method, but the software as it relates to other bits of code can indicate other problem ...

Software complexity is a subjective measure regarding a person’s ability to know. Something complicated when it takes effort to understand a person. The fact is that the complexity of the software is two-dimensional. To understand a piece of code, you need to understand both:

  • what this piece of code should do at runtime, code behavior, is the complexity of business tasks.
  • How a real implementation really reaches a business problem, what was the mental state of the developer when writing code, this is the complexity of the implementation.

The complexity of business tasks lies in the specification of the program and its reduction means working on the behavior of the code itself. On the other hand, we are talking about complex complexity when it comes to implementation complexity : it is fabricated in the sense that it can be reduced without changing the behavior of the code.

0
source share

How will this improve our software?

It may be a trigger for refactoring, but the following metric does not guarantee that all other quality indicators remain unchanged. And tools can track very few indicators. You cannot measure which degree code is understandable.

Will our code become better because, for example, we make 10,000 lines of a file into 4,200 lines of files?

Not necessary. Sometimes larger ones may be more understandable, better structured, and have fewer errors.

Most design templates, for example, “enhance” your code, making it more general and reliable, but often with the cost of added source lines.

0
source share

All Articles