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

nucleotide-count: convert the class to a function #579

Merged

Conversation

siebenschlaefer
Copy link
Contributor

Before PR #550 the constructor was required to validate the input, the member function count(char) had to return the count for a specific nucleotide, the member function nucleotide_counts() had to return a std::map with all four counts.

But PR #550 has changed that significantly. After syncing the tests with the canonical data there's no call to count(char) anymore, so each test looks like a two-step function call:

const nucleotide_count::counter dna("G");
const auto actual = dna.nucleotide_counts();

I'd call that unnecessarily complicated and unidiomatic, there's no longer a good reason to require a class. Let's turn the class counter into a function:

const auto actual = nucleotide_count::count("G");

Before PR exercism#550 the constructor was required to validate the input, the
member function `count(char)` had to return the count for a specific
nucleotide, the member function `nucleotide_counts()` had to return a
`std::map` with all four counts.

But PR exercism#550 has changed that significantly. After syncing the tests with
the canonical data there's no call to `count(char)` anymore, so each
test looks like a two-step function call:

```
const nucleotide_count::counter dna("G");
const auto actual = dna.nucleotide_counts();
```

I'd call that unnecessarily complicated and unidiomatic, there's
no longer a good reason to require a `class`. Let's turn the class
`counter` into a function:

```
const auto actual = nucleotide_count::count("G");
```
Copy link
Contributor

@vaeng vaeng left a comment

Choose a reason for hiding this comment

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

I really like that change. I remember that felt forced. As if you had to use OOP no matter what.

@vaeng vaeng merged commit a421229 into exercism:main Mar 15, 2023
@siebenschlaefer siebenschlaefer deleted the nucleotide-count-class-to-function branch March 16, 2023 15:57
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