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.
In
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:
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.