Skip to content

Refactor options.Config to Remove Pointer for DirectText (Improving Usability and Testing) #30

@supitsdu

Description

@supitsdu

The options.Config struct currently uses a pointer to a string (*string) for the DirectText field. This design choice was initially made to accommodate the return type of flag.String in the ParseFlags() function. However, it has led to increased complexity and challenges in testing and usage due to the need for pointer dereferencing.

Reasoning:

As noted in the PR review, using a pointer for DirectText provided minimal memory optimization benefits and introduced unnecessary complications. Removing the pointer simplifies the code and avoids potential nil pointer errors during testing and subsequent usage.

Proposed Changes:

  1. Remove Pointer: Change the type of the DirectText field in options.Config from *string to string.
  2. Update ParseFlags(): Modify the ParseFlags() function to assign the value returned by flag.String directly to the DirectText field (which is now a string).
  3. Update clipper Package: Ensure that any references to config.DirectText in the clipper package are updated to reflect the change in type.
  4. Update Tests: Adjust unit tests in the clipper_test package to account for the new type of the DirectText field.

Expected Benefits:

  • Simplified Code: Removing the pointer from DirectText will make the code simpler and easier to understand.
  • Improved Usability: Eliminate the need for pointer dereferencing when accessing config.DirectText.
  • Easier Testing: Avoid potential nil pointer issues during testing.
  • Maintain Performance: The performance impact of using a string instead of *string is expected to be negligible in this context.

Originally posted by @ccoVeille in #29 (comment)

Metadata

Metadata

Assignees

No one assigned

    Labels

    good first issueGood for newcomersrefactoringIssues or PRs to improving code structure, without changing its external behaviortestingIssues or PRs specifically related to Go testing frameworks or practices.usability

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions