Skip to content

hamming: create exercise#42

Merged
sshine merged 2 commits intoexercism:masterfrom
glennj:port/hamming
Sep 12, 2019
Merged

hamming: create exercise#42
sshine merged 2 commits intoexercism:masterfrom
glennj:port/hamming

Conversation

@glennj
Copy link
Copy Markdown
Contributor

@glennj glennj commented Sep 12, 2019

No description provided.

@glennj glennj requested a review from sshine September 12, 2019 10:25
Copy link
Copy Markdown
Contributor

@sshine sshine left a comment

Choose a reason for hiding this comment

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

Nice.

A few clarifying questions, and a superfluous linebreak, but otherwise good to go.

}
if {[string length $left] != [string length $right]} {
error "left and right strands must be of equal length"
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looking a few example solutions for other tracks through, does it not suffice to only check for equal length?

With this in mind, the error message will be more generic.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

True. The "check for left/right empty" tests were the most recently added to the canonical data: https://github.com/exercism/problem-specifications/blame/master/exercises/hamming/canonical-data.json

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

What's your thinking about keeping/omitting tests specified in the canonical data, given that the commit refers to this issue: exercism/haskell#796, and the new test speciications seem specific to the Haskell track.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Ah yes, those test cases originate from exercism/haskell#796 and I encouraged that they should be canonical. They were added because of a rather specific situation in ML-like languages where this exact input would fall through all listed cases.

I'd consider them as the simplest cases of the equivalence classes of one being longer than the other, and the other being longer than one, rather than separate equivalence classes. But since they were clearly missing once on Haskell, in spite of having other representatives from that class, maybe that's not true.

I'll let you decide and will approve the PR now.

Copy link
Copy Markdown
Contributor

@sshine sshine Sep 12, 2019

Choose a reason for hiding this comment

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

What's your thinking about keeping/omitting tests

Sorry, I responded later than I realized that you'd asked.

I think we should keep them:

  • Unless they're somehow wrong, having more tests is good.
  • Just because their need arose in a language with pattern matching, they're still good representatives of an equivalence class that must be handled.
  • Avoiding special cases means we can more easily create test generators.
  • We don't need to see them as being anything but an example of mismatching lengths, so I'd rather... ohh...

I realize that the error is different in those two. So if we expect our test suite to be auto-generated, and we don't special-case the generator for this exercise, a correct solution would have to special-case the two.

I realize now that when I approved the PR, I was really only thinking about the Haskell track where distance :: String -> String -> Maybe Int, so no distinction whatsoever. Maybe we should amend this on problem-specifications by making it return the same message in all cases?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I'll let you follow up on problem-specifications. Here, I'll remove the special cases as the length mismatch test will cover all these cases.

Comment thread exercises/hamming/example.tcl
Comment thread exercises/hamming/hamming.tcl Outdated
proc hammingDistance {left right} {
throw {NOT_IMPLEMENTED} "Implement this procedure."
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

What's the reason to use throw vs. error? Should we consistently use one or the other, or is there a reason why throw is better here when error is used in the example solution?

Also, the last linebreak is unnecessary.

Suggested change

Copy link
Copy Markdown
Contributor Author

@glennj glennj Sep 12, 2019

Choose a reason for hiding this comment

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

I think you created the first stub .tcl file using throw, and I've been continuing that usage.

throw is good here because it sets the specific $errorCode:

$ tclsh
% catch {error foo} a b
1
% set b
-code 1 -level 0 -errorstack {INNER {returnImm foo {}}} -errorcode NONE -errorinfo {foo
    while executing
"error foo"} -errorline 1
%
% catch {throw NOT_IMPLEMENTED foo} a b
1
% set b
-errorcode NOT_IMPLEMENTED -code 1 -level 0 -errorstack {INNER {returnImm foo {-errorcode NOT_IMPLEMENTED}}} -errorinfo {foo
    while executing
"throw NOT_IMPLEMENTED foo"} -errorline 1
% set errorCode
NOT_IMPLEMENTED

Do students typically see the example?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Do students typically see the example?

I don't understand the question. What do you mean?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Do students typically see the example?

I don't understand the question. What do you mean?

I have throw in the stub and error in the example. I guess I'm unclear whether you are concerned about confusing the students, or about our own internal consistency.

Copy link
Copy Markdown
Contributor

@sshine sshine Sep 12, 2019

Choose a reason for hiding this comment

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

I understand the question now.

I don't think many students will see the example before they submit, no.

My concern is that students will use throw because it's already there and not know what to put instead of NOT_IMPLEMENTED. I didn't know myself, but it appears that anything can be placed in it and the current test suite will pass.

Looking at the roadmap in #23, I realize that Hamming comes a while after Error Handling, and that if the Error Handling exercise covers both error and throw, we should be fine here.

@sshine sshine merged commit 033356b into exercism:master Sep 12, 2019
@glennj glennj deleted the port/hamming branch September 12, 2019 20:55
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