scitools.com

← Metric catalog

Strict Modified Essential Complexity is one of the source-code metrics Understand computes across 17+ languages — browse them in the GUI, export and track them, or script them with the Python API.

Strict Modified Essential Complexity

API ID: EssentialStrictModified
Languages: Ada
Targets: Packages, Subprograms

Cyclomatic Complexity after graph reduction, except that a decision using a short circuit operator (and then/or else) is treated as unstructured — so it isn't reduced away — while a case statement that survives reduction still only adds one, no matter how many structured paths run through it.

This is Ada-only: and then/or else are Ada's short-circuit boolean operators. Like Essential Complexity, it's computed after reducing well-structured subgraphs out of the control-flow graph, but a decision using and then/or else isn't reduced away, and a case that survives reduction still counts as a single decision point (as in Modified Cyclomatic Complexity) regardless of how many when branches it has.

For example:


procedure Simple_Proc (X : in out Integer) is
begin
  if X < 0 then
    X := 0;
  end if;

  for I in 1 .. X loop
    X := X - 1;
  end loop;
end Simple_Proc;

function Case_Func (Day : Integer) return Integer is
  Result : Integer := 0;
begin
  case Day is
    when 1 =>
      return 10;
    when 2 =>
      Result := 20;
    when 3 =>
      Result := 30;
    when others =>
      Result := 0;
  end case;
  return Result;
end Case_Func;

Simple_Proc has no short-circuit operators or case statement, so it reduces the same way for both metrics: Essential Complexity and Strict Modified Essential Complexity are both 1.

Case_Func's case statement doesn't reduce away, since one branch (when 1) returns early while the others fall through to the final return. Counted normally, that's 3 decision points (when 1, when 2, when 3; when others doesn't count), for an Essential Complexity of 4. Modified counting collapses the whole case to a single decision point instead, for a Strict Modified Essential Complexity of 2.

A decision using and then/or else doesn't reduce away either, and an elsif clause is judged on its own condition. For example, a chain of if A and then B / elsif B or else N > 10 has an Essential Complexity of 1 (fully reduced under plain rules), but under strict modified counting neither clause reduces, so the if, the elsif, and both short circuit operators all remain, for a Strict Modified Essential Complexity of 5.

See Sum, Max, and Average Strict Modified Essential Complexity for aggregated values across a package.

Targets By Language: Configuration: