Ambiguity in the Advanced Enumeration learning curriculum / Boutique Inventory learning exercise

The example:

fibonacci = [0, 1, 1, 2, 3, 5, 8, 13]
…
fibonacci.find { |number| number >= 5} #=> 5

…is ambiguous as to whether #find returns the element or the index of the element. I don’t know if this is something to be fixed or is an intentional “opportunity to learn”. As a noob, I ended up looking it up after I’d assumed incorrectly about it and was getting an error in the exercise–which was maybe a good thing for my learning. I’m curious how the maintainers and experts might feel about it.

IF it is unintentional, and it’s decided that it’s bad, I’ll go ahead and provide a potential solution idea of just changing it (and perhaps also the #select example, if it was intentional to have them be the same) to search for elements >= 3 instead of >= 5?

I think that is just a coincidence that index 5 of the fibonacci seq in the example is also the value 5. Find should return only the first value that fit the condition, not the index.

Select and find act different in ruby so I don’t think the select example should be changed at all.

Personally I can go one way for another for the example change of find to make it less ambiguous, because I think the example on exercism should be simple and just a gateway for people to go out and read the official docs for details. What I think more important is there should be some hyperlinks at the bottom or inside the article so learner can just go there to read more about the subject at hand.

1 Like

I agree that it is coincidental. It does not make sense that you would have to find an index, as the indexes are known, they are addresses, the value is what you would probably intuitively want to find.

Selecting something is different, though, as is noted.

Perhaps finding 3 or 8 would be better to avoid a “Stroop Effect” that seems to be going on here, though, as the index and the element are the same value. (indeed, even the same object)

If the methods are indeed Enumerable methods, we could change “enumeration” to “Enumerable” methods and link to the documentation for Enumerable Array#find. But “enumeration” is not necessarily tied to this, it is all the methods including methods that are not defined by the class’ instance being used, some (many) coming from Enumerable.

But also, I wonder why it is thought that the behavior of find is ambiguous, since the documentation specifically states:

Returns the first element for which the block returns a truthy value.

It states “element” not “index”.

That said, there is prior knowledge that is not necessarily clear, where we state in Bird Count that (at least) some of the methods are Array methods, when they are indeed no, but come from Enumerable instead.

There is something to be said for “lies to children” to be discovered later with some expertise that it is not precisely correct. But I do feel like perhaps this can be addressed by more precise indications in the prior exercise, rather than waiting here to find out that perhaps the documentation is not consulted.

I would not change the select example, though. It seems to be clear, and if the find is changed, it will not be coincidentally the same number we are looking for and should result in selecting [5, 8, 13].

3 Likes

It would.

I think that’s the change that should be made to just remove the confusion! :muscle:t4:

2 Likes

To clarify: I specifically meant that, IF the purpose of providing the code block with all of those Enumerable/Array/Hash functions was to show how they’re to be used, then that example does not do so very well. The Ruby-docs are not ambiguous, and is where I went to figure out my issue.

2 Likes

That would work too… but…

I ended up looking backward to Bird Count exercise, which is also a concept exercise, and it perhaps does not communicate about this topic strongly enough. So there is definitely work that can be done here, but it involves the concept track in terms of Enumerable and enumeration in general.

Ah yes! Apologies. I meant just for the particular issue about this stroop effect :smiley:

1 Like

That is what we really hope would be the action, the habit. We do not intend to “redocument” what is available and canonical.

3 Likes

If you would like to switch up the example (if you feel like it will not stop another student from questioning and learning) I will reopen the pull request (I will be notified of it happening), but also do pleases link that PR to here and here to that PR so that the communication cycle is complete.

If you think that it does potentially push to the documentation, then there is value in that.

This exercise is not coming from Problem Specifications, but it does also exist for other tracks. One might check to see if this might be something they would want as well.

PR submitted:

2 Likes

Approved and brought in.

Thank you!

2 Likes