.. index:: single: cogc_metric .. _cogc_metric/0: .. rst-class:: right **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`` :ref:`code_metrics_utilities ` | ``public`` :ref:`code_metric ` | **Provides:** | :ref:`logtalk::message_tokens//2 ` | **Uses:** | :ref:`list ` | :ref:`logtalk ` | :ref:`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:** |  :ref:`code_metric/0::all/0`  :ref:`code_metric/0::all/1`  :ref:`code_metric/0::all_score/1`  :ref:`options_protocol/0::check_option/1`  :ref:`options_protocol/0::check_options/1`  :ref:`options_protocol/0::default_option/1`  :ref:`options_protocol/0::default_options/1`  :ref:`code_metric/0::directory/1`  :ref:`code_metric/0::directory/2`  :ref:`code_metric/0::directory_score/2`  :ref:`code_metric/0::entity/1`  :ref:`code_metric/0::entity_score/2`  :ref:`code_metric/0::file/1`  :ref:`code_metric/0::file/2`  :ref:`code_metric/0::file_score/2`  :ref:`code_metric/0::format_entity_score//2`  :ref:`code_metric/0::library/1`  :ref:`code_metric/0::library/2`  :ref:`code_metric/0::library_score/2`  :ref:`options_protocol/0::option/2`  :ref:`options_protocol/0::option/3`  :ref:`code_metric/0::rdirectory/1`  :ref:`code_metric/0::rdirectory/2`  :ref:`code_metric/0::rdirectory_score/2`  :ref:`code_metric/0::rlibrary/1`  :ref:`code_metric/0::rlibrary/2`  :ref:`code_metric/0::rlibrary_score/2`  :ref:`options_protocol/0::valid_option/1`  :ref:`options_protocol/0::valid_options/1`   .. contents:: :local: :backlinks: top 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)