Skip to content

list-ops: update to match Kotlin track - #671

Merged
FridaTveit merged 1 commit into
masterfrom
list-ops-update
Jul 7, 2017
Merged

FridaTveit merged 1 commit into
masterfrom
list-ops-update

Conversation

@stkent

@stkent stkent commented Jun 30, 2017

Copy link
Copy Markdown
Contributor

Based on v1.0.0 of the canonical data:

https://github.com/exercism/problem-specifications/tree/28a32203b96ebaecac6a6968831bd66718d8ba30/exercises/list-ops

Plus modifications that are being discussed in

exercism/problem-specifications#826


Reviewer Resources:

Track Policies

@@ -0,0 +1,3 @@
## Hints

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.

Not sure if we do this in other HINTS files, but I like this!


private ListOps() {
// No instances.
}

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.

@FridaTveit would this have provided enough of a starter for you when working on this exercise, do you think? I decided not to add in explicit descriptions of the operations because I think the tests + the type signatures make it possible to deduce the purpose of each operation now?

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.

Yes, this great! This was exactly what I felt it needed. If users need to take some time to think about what the operations do then that's fine, that should be part of the exercise. I just thought it was a bit of a waste for people to have to spend ages just figuring out what the signatures are. So this is perfect! :)

And the .keep file isn't needed anymore now that we have this file :)

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.

The keep file was deleted in this PR already, I think?

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.

Yes, sorry, my mistake :)

@stkent
stkent force-pushed the list-ops-update branch from 4536655 to f82bf81 Compare June 30, 2017 20:22
import static junit.framework.TestCase.assertEquals;
import static junit.framework.TestCase.assertFalse;
import static junit.framework.TestCase.assertNotNull;
import static junit.framework.TestCase.assertTrue;

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.

JUnit 3 ‼️

@FridaTveit FridaTveit left a comment

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.

Looks great! I really good improvement :) I only have one small question and there's a .keep file we don't need.

Also, do you want to change the estimated difficulty as part of this PR? Or do you think it should still be the same difficulty/do you want to do that in a different PR? :)


private ListOps() {
// No instances.
}

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.

Yes, this great! This was exactly what I felt it needed. If users need to take some time to think about what the operations do then that's fine, that should be part of the exercise. I just thought it was a bit of a waste for people to have to spend ages just figuring out what the signatures are. So this is perfect! :)

And the .keep file isn't needed anymore now that we have this file :)

assertFalse(actual.isEmpty());
assertEquals(expected, actual);
@Test
public void testFoldLeftWithDirectionDependentOperationOnNonEmptyList() {

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.

How is this direction dependent? I understand that the operation in itself is but with these numbers you would get the same answer no matter which direction you traverse the list wouldn't you? Wouldn't it be a better test if that wasn't the case?

@stkent stkent Jul 2, 2017 •

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.

The difference between these two cases is due to some subtleties of how the fold function parameter is typed. In particular, note that it is of type

BiFunction<U, T, U>

for the left fold, and of type

BiFunction<T, U, U>

for the right fold. Since T is the type of the list entries, and U is the type of the accumulated value, this means that if we pass the anonymous function (x, y) -> x / y to both folds, we're actually performing slightly different calculations. See this upstream comment and the ones following for some relevant chatter. So what we're actually doing is the following:


If folding from the left:

Step 0: accumulation = 5
Step 1: accumulation = a / c = 5 / 2 = 2
Step 2: accumulation = a / c = 2 / 5 = 0

If folding from the right:

Step 0: accumulation = 5
Step 1: accumulation = c / a = 5 / 5 = 1
Step 2: accumulation = c / a = 2 / 1 = 2

I updated the function signatures in the test suite to use generic parameter labels x and y rather than accumulation and current to make it clearer that we're using the same anonymous function in both cases. It's up to the user to infer from the (provided) type signature how those parameters should be populated. I update the HINTS file to provide a direct link to the section of the fold Wikipedia page relevant to interpretation of these signatures.

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.

Okay. So someone solving the exercise definitely can't traverse the list the wrong way and still pass this test?

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.

?

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 believe that is correct, based on how the anonymous function + method signature combines, yes :)

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.

Great :)

@stkent
stkent force-pushed the list-ops-update branch 2 times, most recently from cada9e9 to bf3984d Compare July 2, 2017 19:19
@stkent

stkent commented Jul 2, 2017

Copy link
Copy Markdown
Contributor Author

What do you think the new exercise difficulty should be, @FridaTveit? I'm thinking it might not need a huge adjustment since we introduce generics quite late, and this touches generics + functional programming concepts! 😱

@FridaTveit

Copy link
Copy Markdown
Contributor

That's true. Maybe change it to 8?

@stkent

stkent commented Jul 3, 2017

Copy link
Copy Markdown
Contributor Author

Sounds good; incoming!

@stkent
stkent force-pushed the list-ops-update branch from bf3984d to 6599e32 Compare July 3, 2017 17:09

@FridaTveit FridaTveit left a comment

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.

Looks great! :) I still have one question about the fold tests but I'm happy for it to be merged :)

assertFalse(actual.isEmpty());
assertEquals(expected, actual);
@Test
public void testFoldLeftWithDirectionDependentOperationOnNonEmptyList() {

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.

?

@FridaTveit
FridaTveit merged commit 0f86212 into master Jul 7, 2017
@stkent
stkent deleted the list-ops-update branch July 8, 2017 15:33
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