cogc_metric — Logtalk 3.100.1

object

# `cogc_metric`

Cognitive complexity metric (approximation). For each non-auxiliary predicate, the score contribution is the number of extra clauses (i.e. number of clauses minus one, for multi-clause branching) plus one if the predicate is directly recursive. The entity score is the sum of all predicate contributions. Protocols are not scored as they cannot define predicates.

Availability:
`logtalk_load(code_metrics(loader))`
Author: Paulo Moura
Version: 1:0:0
Date: 2026-03-14
Compilation flags:
`static, context_switching_calls`
Imports:
`public` code_metrics_utilities
`public` code_metric
Provides:
logtalk::message_tokens//2
Uses:
list
logtalk
numberlist
Remarks:

> - Limitations: The reflection API does not expose control constructs such as cuts, conditionals, or disjunctions. This metric approximates cognitive complexity using only clause-level branching and direct recursion.

> - Branching: A predicate with N clauses contributes N-1 to the score, representing the N-1 extra choices a reader must track.

> - Recursion: A predicate that directly calls itself (within the same entity) contributes an additional 1 to the score.

> - Score interpretation: The score is represented by a non-negative integer. Higher scores indicate predicates or entities that are harder to understand due to more branching choices or self-recursion. A score of 0 means all predicates are single-clause and non-recursive.

> - Aggregation: File, directory, and library scores are computed by summing the individual entity scores.

Inherited public predicates:
all/0 all/1 all_score/1 check_option/1 check_options/1 default_option/1 default_options/1 directory/1 directory/2 directory_score/2 entity/1 entity_score/2 file/1 file/2 file_score/2 format_entity_score//2 library/1 library/2 library_score/2 option/2 option/3 rdirectory/1 rdirectory/2 rdirectory_score/2 rlibrary/1 rlibrary/2 rlibrary_score/2 valid_option/1 valid_options/1

## Public predicates

(no local declarations; see entity ancestors if any)

## Protected predicates

(no local declarations; see entity ancestors if any)

## Private predicates

(no local declarations; see entity ancestors if any)

## Operators

(none)