Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor: Convert some Option[string] to string #90

Merged
merged 1 commit into from
Oct 30, 2020

Conversation

ee7
Copy link
Member

@ee7 ee7 commented Oct 30, 2020

There isn't much reason to use Option[string] for exercise and probSpecsDir - we can just test whether the string is empty.

This also allows us to consider setting the default value of probSpecsDir to .problem-specifications in the future, which better models the current behaviour.

Note that (both before and after this commit) if we run any of:

canonical_data_syncer -p=
canonical_data_syncer -p
canonical_data_syncer -e=
canonical_data_syncer -e

Then we see an error message like:

Error: '-p' was given without a value

There isn't much reason to use `Option[string]` for `exercise` and
`probSpecsDir` - we can just test whether the string is empty.

Note that (both before and after this commit) if we run any of:
    canonical_data_syncer -p=
    canonical_data_syncer -p
    canonical_data_syncer -e=
    canonical_data_syncer -e

Then we see an error message like:
    Error: '-p' was given without a value
@ee7 ee7 requested a review from ErikSchierboom as a code owner October 30, 2020 09:53
Copy link
Member

@ErikSchierboom ErikSchierboom left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do feel that we're sacrifing readability a bit here. conf.exercise.isNone to me is more descriptive for what is happening than conf.exercise.len == 0. But I don't feel strongly about it.

@ErikSchierboom ErikSchierboom merged commit 3f28109 into exercism:master Oct 30, 2020
@ee7 ee7 deleted the refactor-cli-no-option branch October 30, 2020 11:00
@ee7
Copy link
Member Author

ee7 commented Oct 30, 2020

I actually prefer it this way.

I can agree that .isNone and .isSome are "more descriptive" than the corresponding .len == 0 and .len > 0. But I personally find the latter more "readable" - it avoids the noise, and otherwise a reader might wonder whether there's some subtle behaviour that makes Option necessary. For example, they might ask: "do we distinguish between some("") and none[string]?"

It's also good enough for Nim and Nimble (see in particular nimbleDir, which is a similar "option with a value").

There's also the argument of "if probSpecsDir is Option[string], then check should be Option[bool]".

ee7 added a commit to ee7/exercism-configlet that referenced this pull request Jan 21, 2021
There isn't much reason to use `Option[string]` for `exercise` and
`probSpecsDir` - we can just test whether the string is empty.

Note that (both before and after this commit) if we run any of:
    canonical_data_syncer -p=
    canonical_data_syncer -p
    canonical_data_syncer -e=
    canonical_data_syncer -e

Then we see an error message like:
    Error: '-p' was given without a value
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants