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

Switch semantics of filterLongerThan and filterShorterThan #1587

Merged
merged 1 commit into from
Nov 5, 2024

Conversation

JoelCourtney
Copy link
Contributor

When I made the filterShortThan and filterLongerThan methods in the timeline library, I had a choice of semantics, either "filterShorterThan filters OUT intervals shorter than" or "filterShorterThan filters SUCH THAT all intervals are shorter than". I chose the first, but in practice I get confused every time I use these functions. This is because with all other filter-like functions such as highlightEqualTo or isolateTrue, I named them in the pattern <operation><predicate>. So in highlightEqualTo("x"), if the segment is equal to "x", it is highlighted. Unfortunately I broke that pattern with filterLonger/ShorterThan; in filterShorterThan the object is retained if it doesn't match the shorter-than predicate.

I understand that this is the absolute worst kind of breaking change. It doesn't just invalidate existing code, it completely reverses what it does. But I can't think of another way that isn't more work than it's worth. I'm hoping the impact is pretty small since procedural scheduling is still a new feature.

@JoelCourtney JoelCourtney self-assigned this Oct 25, 2024
@JoelCourtney JoelCourtney requested a review from a team as a code owner October 25, 2024 23:08
@Mythicaeda Mythicaeda added the breaking change A change that will require updating downstream code label Nov 4, 2024
@Mythicaeda
Copy link
Contributor

Mythicaeda commented Nov 4, 2024

I think the naming of these functions needs to be revisited, as if I use filterShorterThan("X"), I would expect the filter to remove everything shorter than X, which is the current behavior on develop AFAIU.

@dandelany
Copy link
Collaborator

dandelany commented Nov 4, 2024

the naming of these functions needs to be revisited

This PR is the revisitation 🙂

if I use filterShorterThan("X"), I would expect the filter to remove everything shorter than X

I disagree, I think the proposed change is more intuitive & closer to standard - as @JoelCourtney notes, it makes it more consistent with things like highlightEqualTo or isolateTrue. A stronger argument IMHO is that pretty much all languages that have a filter function use a syntax like filter(predicate, subject) where predicate is the thing you're including. So eg. if you had a isOdd function, filter(isOdd, myArr) will return all things that are odd, not filter out (remove) things that are odd, so devs who commonly use filter will likely expect this convention.

Copy link
Collaborator

@dandelany dandelany left a comment

Choose a reason for hiding this comment

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

I asked a few more people for opinions on this today (@mattdailis @joswig and @jmorton ) to try and reach consensus, and where we landed was:

  • filterX in general can be a confusing name, in future we should consider naming things like this keepX or removeX
  • However, doing ^this would a more far-reaching change than this PR needs right now & would take some more time/buy-in
  • Given the choice between filterX meaning "keep X" or "filter out all X's", everyone I asked thought that "keep X" was the more intuitive choice given the syntax of filter() mentioned above
  • Therefore I think we should approve & merge this PR

@dandelany dandelany force-pushed the fix/switch-filter-by-duraitons branch from 0c948e7 to 3801157 Compare November 5, 2024 21:54
@dandelany dandelany merged commit 35c97fe into develop Nov 5, 2024
10 checks passed
@dandelany dandelany deleted the fix/switch-filter-by-duraitons branch November 5, 2024 23:19
@joswig joswig added this to the FY25 Q1 - Ad Hoc Improvements milestone Nov 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking change A change that will require updating downstream code
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

4 participants