Skip to content

McCabe Complexity #264

Description

@cowlicks

This issue on another project puts it better than I can:

McCabe complexity is a number that represents the number of different way one can traverse through a method. It is recommended that this measure never exceeds 10. Running a complexity checker on openspending results in 10 methods with too high complexity (current version). These should all be fixed to keep the code clean and maintainable.

To see the errors I would recommend installing flake8 (can run McCabe's complexity checker and more), navigating to the root of the repo and running:

flake8 --max-complexity=10 --select=C distarray

the output is:

distarray/externals/six.py:559:1: C901 'print_' is too complex (22)
distarray/local/localarray.py:1601:1: C901 'LocalArrayBinaryOperation.__call__' is too complex (10)
distarray/plotting/plotting.py:68:1: C901 'plot_array_distribution' is too complex (15)

The six stuff isn't our problem. But the other functions definitely look too complex.

This is low priority but I thought it was interesting. This might be a good issue for someone to tackle if they want to become acquainted with the codebase.

Activity

  1. added this to the wishlist milestone on Mar 31, 2014
  2. rkern commented on Apr 1, 2014

    @rkern
    Member

    I would recommend simply applying your own judgement. If you read a method that you think is too complex, for whatever reason, please open an issue to have it refactored. McCabe complexity has been shown to have no predictive power over a simple count of the number of source lines of code, and it's almost a truism that more code => more bugs. As far as I can tell from the literature, there is no empirical backing for the arbitrary limit of 10. Using McCabe complexity screening in this fashion just causes meaningless churn without actually improving the codebase.

    Our collective subjective judgements about complexity are the actual ground truth here: if one of us reads a method and think it's too complex, then it's too complex. If no one who reads it thinks it's too complex, it's not too complex, no matter what McCabe says. And if no one reads it, then it doesn't matter how complex it is. :-)

  3. modified the milestones: 0.2, wishlist on Apr 2, 2014
  4. modified the milestones: wishlist, 0.2 on Apr 2, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions