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:
Remove Pointer: Change the type of the DirectText field in options.Config from *string to string.
Update ParseFlags(): Modify the ParseFlags() function to assign the value returned by flag.String directly to the DirectText field (which is now a string).
Update clipper Package: Ensure that any references to config.DirectText in the clipper package are updated to reflect the change in type.
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.
The
options.Config
struct currently uses a pointer to a string (*string
) for theDirectText
field. This design choice was initially made to accommodate the return type offlag.String
in theParseFlags()
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:
DirectText
field inoptions.Config
from*string
tostring
.ParseFlags()
: Modify theParseFlags()
function to assign the value returned byflag.String
directly to theDirectText
field (which is now astring
).clipper
Package: Ensure that any references toconfig.DirectText
in theclipper
package are updated to reflect the change in type.clipper_test
package to account for the new type of theDirectText
field.Expected Benefits:
DirectText
will make the code simpler and easier to understand.config.DirectText
.string
instead of*string
is expected to be negligible in this context._Originally posted by @ccoVeille in https://github.com/supitsdu/clipper/pull/29#discussion_r1657817850_