For example, to understand
if (obj.index == 0 && (f_mode > 3 || state[1] != null))
you need to know
* What does obj represent
* Under what circumstance does obj have an index of 0
* Why we are interested in that circumstance for what we are trying to achieve
* What does f_mode represent
* Under what circumstances is f_mode greater than 3
* etc etc etc
You need to know at least 10 things to understand it. However, if we break it up and replace it with
if (Membership.IsExpired)
then we need to know 0 things to understand it.
Is there some sort of principle that represents the number of things you need to know? A sort of Things You Need To Know To Understand This Index? Something that is a countable unit, so that you could say that one block of code has an index of 17 (i.e. you need to know 17 things to understand it) while another block of code has an index of 2?
We could start from a baseline assumption that the reader knows the coding principles themselves. The reader needs to know how an if-statement works, for example, but that would not be included in the index. One might argue about whether more obscure coding tricks should be included in the index or not.
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.