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

Add practice exercise binary-search-tree #609

Merged
merged 3 commits into from
Oct 3, 2023
Merged

Conversation

jiegillet
Copy link
Contributor

I've been away for a while, but I'm trying to get back in.
Practice exercises usually motivate me, so here is a nice little one :)

Copy link
Contributor

@ceddlyburge ceddlyburge left a comment

Choose a reason for hiding this comment

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

This all looks good. Presumably the copy and tests are all standard and shared between the other languages so don't need to be examined in too much detail?

exercises/practice/binary-search-tree/tests/Tests.elm Outdated Show resolved Hide resolved
@ceddlyburge
Copy link
Contributor

@pwadsworth, do you want to give this a review? It seems like you are keen to get involved, and reviewing stuff is very useful for us, and a good way of getting familiar with the codebase and the (sometimes unwritten) conventions and things like that.

I remember Jie reviewing one of my PRs before he became a maintainer, and obviously we all review each others code all the time.

@jiegillet
Copy link
Contributor Author

This all looks good. Presumably the copy and tests are all standard and shared between the other languages so don't need to be examined in too much detail?

Mostly, but I changed the function names, I thought the canonical ones weren't very good: data -> makeTree and sortedData -> sort.

@ceddlyburge
Copy link
Contributor

Welcome back! I agree about the canonical names. Is it worth raising a PR in the repo to update them for everybody?

@pwadsworth
Copy link
Contributor

@pwadsworth, do you want to give this a review? It seems like you are keen to get involved, and reviewing stuff is very useful for us, and a good way of getting familiar with the codebase and the (sometimes unwritten) conventions and things like that.

Love to. I should have some time to go over it later today.

Copy link
Contributor

@pwadsworth pwadsworth left a comment

Choose a reason for hiding this comment

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

This looks pretty good to me. My only recommendations are to adapt some of the terms to match Elm concept of no null values and immutability i.e. using the term parameter/argument instead of variable.


Say we have the array `[1, 3, 4, 5]`, and we add 2 to it so it becomes `[1, 3, 4, 5, 2]`.
Now we must sort the entire array again!
We can improve on this by realizing that we only need to make space for the new item `[1, nil, 3, 4, 5]`, and then adding the item in the space we added.
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this needs to be adapted to Elm to avoid the invalid code (list with multiple types), and the use of nil since a big part of Elm is the deliberate effort not to use it.

Copy link
Contributor

Choose a reason for hiding this comment

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

This is a good point I think, and happens because this copy comes from the canonical source. I'm not even sure that line 9 adds much anyway, so maybe we could just remove it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We can't modify the instructions, they are standard for all tracks. At best, we can add an addendum, but I don't think it's worth it, many exercises are very vague, and in Exercism, tests are king.



type BinaryTree
= Nil
Copy link
Contributor

Choose a reason for hiding this comment

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

Recommend renaming Nil --> Empty to avoid confusion with Elm not supporting the concept of nil.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think Nil in a custom type is fairly idiomatic in Elm, although I'm not quite sure. Nothing is used within Maybe, and other modules tend to use something else to avoid a name clash as Maybe is so common, and I think Nil is often what people go for.

Copy link
Contributor

Choose a reason for hiding this comment

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

...Nothing is used within Maybe, and other modules tend to use something else to avoid a name clash as Maybe is so common, and I think Nil is often what people go for.

I was recommending a custom type 'Empty' for that reason. Either way, I don't think it's a significant point, just a more idiomatic option.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I also thought Nil was quite idiomatic in Elm, but most tutorials I could find in my extensive 5-minute search reported using Empty. Maybe it's more common in Haskell?
Anyway, made the change in d09f956



type BinaryTree
= Nil
Copy link
Contributor

Choose a reason for hiding this comment

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

Recommend renaming Nil --> Empty to avoid confusion with Elm not supporting the concept of nil.

@ceddlyburge
Copy link
Contributor

Hi @jiegillet , I think this all looks good, do you want to merge it whenever you are happy?

@jiegillet jiegillet merged commit 2b3423e into main Oct 3, 2023
5 checks passed
@jiegillet jiegillet deleted the jie-binary-search-tree branch October 3, 2023 12:01
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.

3 participants