1

I've been working on improving an existing library to be more maintainable after trying to implement a feature I wanted and found the code to be hard to alter.

The library is a node.js grunt plugin called grunt-contrib-jshint and my implementation is in a repo called grunt-jshint-bfs.

I've run a code analysis tool called plato that generates a source analysis report that includes metrics line total/average lines of code, maintainability and estimated errors in an effort to compare the code bases for code quality purposes.

The trouble I'm having is comparing the estimated errors between the two projects, since one has 2 files and the other has many more files it would seem that the exposure to errors would increase, or am I reading that wrong?

Here is a link to my repo's report and the grunt-contrib-jshint report for comparison.

1

I think you're reading that wrong. Based on reading the two reports, it appears that Plato infers an estimated error value from the length and complexity of the code. Longer, more complex functions tend to have higher estimated error values. Unfortunately, Plato does not provide any documentation (that I could find) for its algorithms and approaches, short of the source code itself, and a couple mentions of the complexity and lint libraries it uses. This tells me it is not a serious tool, though its reports look great.

Distributing functions across multiple files (without changing the functions themselves) should make no difference to the total error estimation. Plato does, however, seem to favor shorter source files, so you'll make the tool happier by moving functions to more files. That's not a big justification for doing so, IMO. It is also unfortunate that Plato provides so few project-wide totals for the various metrics it generates. Division of source into files is arbitrary, but the totals across all files are what matters.

As a comparison, here's Plato's report on jquery. It shows estimated error values well above 1 for many files. Does this mean that jquery (which is used on a significant fraction of the web pages in existence these days) has that many errors? I doubt it. Jquery, due to its heavy use, is also heavily tested, and probably nearly bug-free.

I think you should take Plato's results with a grain of salt. It uses some static analysis tools (and not particularly sophisticated ones, IMO) and bulk measurements that are not good metrics for coding style and engineering quality. Instead I recommend you trust your intuition about code quality and develop your sense of code smells [Wikipedia, Jeff Atwood].

And lastly, remember that while reducing complexity is a worthy goal, some code simply needs to be complex. Artificially diluting natural complexity (perhaps by many layers of subroutines) can render it unreadable by other programmers. Write a good comment and trust your colleagues to handle something a little hard.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.