A word for “the number of things you need to know to understand the code”?

  • In

      if (Membership.IsExpired)
    
    You still need to know what Membership represents, that it has a IsExpired field, that that is a Boolean, and what it means.

    Most of it is in the business domain, though.

    You may want to start at https://en.wikipedia.org/wiki/Software_metric, which has links to methods both for estimating complexity before a line of code is written and for estimating complexity of existing code. For the latter, examples are:

      https://en.wikipedia.org/wiki/Halstead_complexity_measures
      https://en.wikipedia.org/wiki/Cyclomatic_complexity
    
    AFAIK most of them estimate the complexity of multiple lines of code/functions/entire programs.

    I don’t think there is agreement as to the usefulness of this, and if so, which method is the best, or whether it’s possible to measure software complexity at all (for the latter, I think everybody’s gut feeling says “yes”, but I don’t think every person would even place different program fragments in the same order of complexity (example: foo.map.filter(…) versus a for loop with a nested if. Which one is deemed simpler depends on one’s pre-existing knowledge)

    I also think we can only estimate program complexity roughly, and wouldn’t go as far as calling anything a metric.

  • What about depth? What if we said your first sentence was 8 deep. One layer for each reference (obj.index, f_mode, state[1]), +1 layer for each statement: == 0, > 3, != null, &&, and (…).

    Giving literature and specific sentences reading levels is similar to what you’re asking.

    One expression, such as ‘obj.index’, might itself be very deep: obj.index, object and its properties, function, perhaps what created it, and so on.

    I don’t know that ‘depth’ is the word you were looking for, perhaps there’s a fancy scientific word to be found. If I wanted to get into it, I’d look into linguistics research on quantifying comprehension and related topics.

  • GNU's complexity[1] tool calculates something like what you're talking about for procedures in C programs, and calls the result a "complexity score", although I don't think it accounts for variable names, nor magic integers.

    [1] - https://www.gnu.org/software/complexity/manual/complexity.ht...

  • You might look to psychology’s concepts of “cognitive load” and “working memory”.

  • I've always called this "self-commenting code". No need to overthink it.