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

exercises(resistor-color-duo): should not silently ignore additional colors #202

Closed
dithpri opened this issue Mar 1, 2023 · 3 comments · Fixed by #203
Closed

exercises(resistor-color-duo): should not silently ignore additional colors #202

dithpri opened this issue Mar 1, 2023 · 3 comments · Fixed by #203
Assignees

Comments

@dithpri
Copy link

dithpri commented Mar 1, 2023

https://github.com/exercism/zig/blob/main/exercises/practice/resistor-color-duo/test_resistor_color_duo.zig#L42-L47

This test expects the code to silently ignore any additional values in the input array.
This pretty much goes against the Zig way of doing things, the hidden assumption can lead to bugs.

$ zig zen

 * Communicate intent precisely.
 * Edge cases matter.
 * Favor reading code over writing code.
 * Only one obvious way to do things.
 * Runtime crashes are better than bugs.
 * Compile errors are better than runtime crashes.
[...]

The function should return an error instead of silently continuing when the passed in slice is longer than 2 elements.

@github-actions
Copy link

github-actions bot commented Mar 1, 2023

Hello. Thanks for opening an issue on Exercism. We are currently in a phase of our journey where we have paused community contributions to allow us to take a breather and redesign our community model. You can learn more in this blog post. As such, all issues and PRs in this repository are being automatically closed.

That doesn't mean we're not interested in your ideas, or that if you're stuck on something we don't want to help. The best place to discuss things is with our community on the Exercism Community Forum. You can use this link to copy this into a new topic there.


Note: If this issue has been pre-approved, please link back to this issue on the forum thread and a maintainer or staff member will reopen it.

@github-actions github-actions bot closed this as completed Mar 1, 2023
@ee7 ee7 self-assigned this Mar 1, 2023
@ee7
Copy link
Member

ee7 commented Mar 1, 2023

Thanks. I'm gradually getting around to cleaning up things like this. I agree that the current implementation isn't great.

I'm leaning towards removing that test case, and changing the function signature from

pub fn colorCode(colors: []const ColorBand) anyerror!isize {

to

pub fn colorCode(colors: [2]ColorBand) isize {

given that we probably have enough exercises to practice error sets and input validation. What do you think?

@ee7 ee7 reopened this Mar 1, 2023
@ee7 ee7 changed the title Resistor Color Duo should not silently ignore additional colors exercises(resistor-color-duo): should not silently ignore additional colors Mar 1, 2023
@dithpri
Copy link
Author

dithpri commented Mar 3, 2023

Thanks. I'm gradually getting around to cleaning up things like this. I agree that the current implementation isn't great.

I'm leaning towards removing that test case, and changing the function signature from

pub fn colorCode(colors: []const ColorBand) anyerror!isize {

to

pub fn colorCode(colors: [2]ColorBand) isize {

given that we probably have enough exercises to practice error sets and input validation. What do you think?

Yes, that's actually even better!

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 a pull request may close this issue.

2 participants