Skip to content

Incremental refactoring of complex functions via extract-on-touch markers #104

@amc-corey-cox

Description

@amc-corey-cox

Summary

Several functions in the codebase have grown large and complex, making them harder to maintain, test, and extend. Rather than a big-bang refactor, this issue tracks an incremental approach: add markers to guide developers to extract methods as they touch the code.

Problem

ObjectTransformer.map_object (~190 lines)

The main transformation function has an 8-branch if/elif chain for slot derivation strategies:

  • slot_derivation.value
  • slot_derivation.unit_conversion
  • slot_derivation.expr
  • slot_derivation.populated_from
  • slot_derivation.sources
  • slot_derivation.object_derivations
  • default fallback

Each new feature (pivot #103, offset #96, cross-class lookup #97) adds another branch.

eval_utils.eval_ (~100 lines)

Type-dispatch function with 15+ branches for AST node types. Will grow if expression language expands (#98).

Approach

  1. Add a developer note at the top of each function explaining the extract-on-touch pattern
  2. Add # EXTRACT: markers at each branch with suggested method signature
  3. Point developers to the new test framework (tests/test_transformer/test_object_transformer_new.py)
  4. As features are added or bugs fixed, extract the touched section

Benefits

Checklist

  • Add markers to ObjectTransformer.map_object
  • Add markers to eval_utils.eval_
  • Document the pattern in contributing guide (optional)

Related Issues

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions