7.9 Ask the owner for a fact it already computes

Rule: §7.9 in the code standards, its closing sentence on accessors.

Why

Rule 7.9 puts a shared decision in the module that owns its fact. That is not enough when the owner keeps the fact to itself: each caller then rebuilds it from the owner’s lower-level output, and the rebuild is a copy of the owner’s own logic. Every copy has to pick the same key and the same default, and the one that drifts gives a wrong answer with no error. When the owner already computes the fact internally, it exposes it as an accessor and callers ask for it.

Good

DeclaredTypeFitter owns the property-list lookup (property_entry) and reads a property’s declared type from it inside fit and _declares_typed_array. It exposes that fact beside property_entry, and its own two reads share the same private helper (addons/godot_mcp_toolkit/contract/declared_type_fitter.gd:114-125):

## The [enum Variant.Type] [param target]'s property list declares for
## [param property], or [constant @GlobalScope.TYPE_NIL] when the list has no such
## property or declares it as a Variant. Headers are skipped as
## [method property_entry] skips them.
static func declared_type(target: Object, property: String) -> int:
	return _entry_type(property_entry(target, property))


## The [enum Variant.Type] the property-list [param entry] declares, or
## [constant @GlobalScope.TYPE_NIL] for an empty entry.
static func _entry_type(entry: Dictionary) -> int:
	return int(entry.get("type", TYPE_NIL))

Each writer asks for it (addons/godot_mcp_toolkit/commands/node_commands.gd:281-282, _set_property_scalar_single; the same call at node_commands.gd:421, :941 and commands/scene_commands.gd:517, :849):

var bare_path := BarePathCheck.bare_path_message(property_name, raw_value,
		DeclaredTypeFitter.declared_type(node, property_name))

A caller that already holds the entry for another reason reads its type from that entry, as resource_commands.gd does after its unknown-property check (addons/godot_mcp_toolkit/commands/resource_commands.gd:70, :78).

Bad

A writer that rebuilds the declared type from property_entry’s raw dictionary, repeating the "type" key and the TYPE_NIL default at each call site:

var bare_path := BarePathCheck.bare_path_message(property_name, raw_value,
		int(DeclaredTypeFitter.property_entry(node, property_name).get("type", TYPE_NIL)))

This shape is not in the tree; the five writers listed above all use the accessor.

Source

The maintainers’ decision, applying 7.4’s “one class owns the fact” to a fact the owner already computes. Background: Ousterhout’s information leakage, in A Philosophy of Software Design (chapter notes: https://danlebrero.com/2021/02/24/philosophy-of-software-design-summary/).


This site uses Just the Docs, a documentation theme for Jekyll.