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

More consistency #3000

Closed
wants to merge 12 commits into from
Closed

Conversation

travisbrown
Copy link
Contributor

@travisbrown travisbrown commented Aug 22, 2019

Update

Because some of these fixes are more controversial than I expected, I've split the easy ones out into separate PRs:

I'm hoping we can get at least these merged before 2.0, even if the rest has to wait for 2.1.

Original description

There's currently a lot of inconsistency in Cats, both in the implementation and in the public API. I know this isn't something most people care about, but I hate it, and even for normal people I imagine it has to make contributing and reading the code harder than it should be. This PR aims to fix a few things that can be fixed without breaking binary compatibility in Cats 2, and to put us in a better position to make things even less horrible in Cats 3!

It does break source compatibility, it breaks it all over the place, but in ways that shouldn't affect normal usage. This is part of the reason I'd really like to get these changes into 2.0.0.

Misnamed instances

Most of these changes are pretty mechanical. I see an Eq instance named zipNelEq, I get extremely angry, I deprecate it, remove its implicit, make it package private, copy the implementation, rename it catsDataEqForZipNonEmptyList or whatever it is it actually should be, make sure validateBC still passes on all Scala versions, and then repeat dozens of times for the rest of the misnamed stuff. In some cases I've also had to add new BinCompat traits for misnamed instances defined in traits (thanks to 2.11).

SortedSet and SortedMap instances

This is one of the bigger changes. Previously we only had instances for cats-kernel type classes (Eq, Monoid, etc.) for SortedSet and SortedMap in cats-core. I don't know why, but I don't think there's a good reason for it. To make things even more confusing, some of the instances for these types in cats-core followed the cats-kernel instance naming convention. I've moved these instances into cats-kernel and done all the necessary juggling to keep from breaking bincompat in cats-core.

Cleaner public API

I've also made all (or approximately all) BinCompat and prioritization traits private to the smallest possible enclosing package (I'm pretty confident the BinCompat ones are all done, but the prioritization ones are easier to miss). Some of these were already package-private, but apparently at random. There's no good reason for them to be in the public interface, so they're gone now.

@@ -9,7 +9,7 @@ import annotation.tailrec

trait FunctionInstances extends cats.kernel.instances.FunctionInstances with Function0Instances with Function1Instances

trait FunctionInstancesBinCompat0 {
private[instances] trait FunctionInstancesBinCompat0 {
Copy link
Contributor

Choose a reason for hiding this comment

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

I am not sure about introducing a BinCompat trait to fix a typo. The plan is to branch out scala 2.11 code right after 2.0 release. Which means we shall be able to leave the typo in the 2.11 code and fix it in master branch without an extra bincompat trait.

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 can pull these parts out, but in my view it'd be better to get all the instance name-related source compat breakage out of the way at once, instead of spreading it across 2.0 and 2.1.

Copy link
Contributor

Choose a reason for hiding this comment

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

The source breakage is highly unlikely to affect anyone (and if anyone it would be a super quick fix on compilation time), but the extra trait will be left there for a very long time.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So you're saying that breaking source compat in 2.x releases is acceptable?


override def eqv(s1: SortedSet[A], s2: SortedSet[A]): Boolean =
StaticMethods.iteratorEq(s1.iterator, s2.iterator)
private[instances] trait SortedSetInstancesBinCompat1 extends LowPrioritySortedSetInstancesBinCompat1 {
Copy link
Contributor

Choose a reason for hiding this comment

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

same concern here, introducing a bincomp trait to fix an inconsistent placement while we should be able to fix this right after 2.0 release without it

@@ -80,7 +80,7 @@ therefore name our implicits according to the following rules:
- If the instance is for multiple type classes, use `InstancesFor` instead of a type class name.
- If the instance is for a standard library type add `Std` after the package. i.e. `catsStdShowForVector` and `catsKernelStdGroupForTuple`.

As an example, an implicit instance of `Monoid` for `List` defined in the package `Kernel` should be named `catsKernelMonoidForList`.
As an example, an implicit instance of `Monoid` for `List` defined in the package `Kernel` should be named `catsKernelStdMonoidForList`.
Copy link
Contributor

Choose a reason for hiding this comment

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

I am not sure if the renaming of these catskernelXXXX instances are worth the extra code due to BC
The std in implicit names in cats-core was due to the fact that cats.instances package was used to be cats.std. And instances in cats.kernel.instances don't have the instance package name in their names because having instances in an instance name is kind of redundant. We have this long name rule in place simply so that contributors can easily come up with long unique name for these implicit defs to avoid potential conflict with other libraries. I agree that ideally we should keep it consistent but I think we are paying too much a cost for this kind of rename fix.

@codecov-io
Copy link

Codecov Report

Merging #3000 into master will decrease coverage by 0.61%.
The diff coverage is 58.65%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #3000      +/-   ##
==========================================
- Coverage   93.75%   93.13%   -0.62%     
==========================================
  Files         366      368       +2     
  Lines        6935     6981      +46     
  Branches      185      184       -1     
==========================================
  Hits         6502     6502              
- Misses        433      479      +46
Impacted Files Coverage Δ
core/src/main/scala/cats/syntax/list.scala 100% <ø> (ø) ⬆️
...ain/scala/cats/kernel/instances/SetInstances.scala 100% <ø> (ø) ⬆️
...n/scala/cats/kernel/instances/QueueInstances.scala 100% <ø> (ø) ⬆️
...in/scala/cats/kernel/instances/ListInstances.scala 100% <ø> (ø) ⬆️
core/src/main/scala/cats/syntax/bitraverse.scala 100% <ø> (ø) ⬆️
.../scala/cats/kernel/instances/OptionInstances.scala 100% <ø> (ø) ⬆️
...re/src/main/scala/cats/syntax/traverseFilter.scala 100% <ø> (ø) ⬆️
core/src/main/scala/cats/data/Binested.scala 100% <ø> (ø) ⬆️
core/src/main/scala/cats/instances/list.scala 100% <ø> (ø) ⬆️
core/src/main/scala/cats/instances/option.scala 100% <ø> (ø) ⬆️
... and 22 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8c031e5...6639667. Read the comment docs.

@travisbrown
Copy link
Contributor Author

Closing this since the important parts got split out and merged in separate PRs. Maybe we can revisit the rest after the 2.11 code split.

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