Skip to content

Code Quality: Address String Heavy Function Arguments and Primitive Obsession in Internal Module #974

@coderabbitai

Description

@coderabbitai

Problem Description

This issue tracks two code quality problems identified by CodeScene static analysis in the internal module:

1. String Heavy Function Arguments

  • Current state: 48.0% of all arguments to the 32 functions in the internal module are strings
  • Threshold exceeded: The recommended threshold is 39.0%
  • Impact: This indicates potential overuse of primitive string types where more specific domain types would be more appropriate

2. Primitive Obsession

  • Current state: 68.0% of all function arguments are primitive types (string, int, bool, etc.)
  • Threshold exceeded: The recommended threshold is 40.0%
  • Impact: This is a code smell indicating that the code may benefit from introducing domain-specific types

Why These Issues Should Be Fixed

String Heavy Arguments Problems:

  1. Type Safety: Strings provide no compile-time validation of content format or constraints
  2. API Clarity: Function signatures become unclear about what specific type of string is expected
  3. Runtime Errors: Easy to pass wrong string values (e.g., passing a file path where a directory name is expected)
  4. Maintainability: Harder to refactor and evolve the API

Primitive Obsession Problems:

  1. Domain Modeling: Primitives don't express business domain concepts effectively
  2. Validation: Validation logic gets scattered instead of being encapsulated in types
  3. Documentation: The code becomes less self-documenting
  4. Refactoring: Changes to data representation require touching many places

Affected Areas

The issues are concentrated in the src/internal/ module, which contains the core application logic including:

  • model.go - Main application model with complex state management
  • File panel operations and management
  • UI state handling and rendering
  • File system operations

Potential Solutions

  1. Introduce Domain Types: Replace string parameters with specific types like FilePath, DirectoryPath, PanelID, etc.
  2. Create Value Objects: For commonly used combinations of primitives
  3. Use Enums/Constants: For string parameters with limited valid values
  4. Struct Parameters: Group related parameters into meaningful structs

Context

This issue was identified during PR #973 review. The PR has grown large, so addressing these architectural improvements is being deferred to maintain focus on the primary objectives.

Related PR: #973
Reporter: @lazysegtree

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions