-
Notifications
You must be signed in to change notification settings - Fork 111
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
Removes Observable methods that also have a Scheduler parameter counterpart #43
Conversation
…ameter counterpart with a default Scheduler
…thods Did not remove some Scheduler parameter counterpart method candidates or add a default Scheduler value, due to various reasons for these methods: ``` Error:(106, 7) in trait Observable, multiple overloaded alternatives of method tumblingBuffer define default arguments. trait Observable[+T] def tumblingBuffer(Duration) def tumbling(Duration, Int) def replay(Int, Duration) def replay(Int) def replay(Duration) def takeRight(Int, Duration) def timeout[U >: T](Duration, Observable[U]) def repeat def timer(Duration, Duration) ``` ``` No default Scheduler defined in RxJava: def sliding(Duration, Duration, Int, Scheduler) def replay[R](Observable[T] => Observable[R], Duration, Scheduler) ``` ``` Does not operate on a specific Scheduler by default: def replay[R](Observable[T] => Observable[R], Int) def replay[R](Observable[T] => Observable[R]) ```
…vable methods using default Schedulers
Now that's much nicer :-) Thanks also for the list in the commit message of 362db2a. The "multiple overloaded alternatives of method xxx define default arguments" error is very annoying: It's not possible to have several overloads with default arguments, even if there's no ambiguity. There are some answers on stackoverflow why it doesn't work, but I'm not quite satisfied by them... The problem is that now most methods have nice default scheduler arguments, but some do not but still silently just choose a default scheduler. This is very misleading. So far I see the following solutions to the default schedulers problem:
I'm not happy with any of these. Any ideas? |
Can we get a list of those? |
It's the first list of the three lists in the commit message of jbripley@362db2a. |
In my order of preference: 2: Breaks a lot of existing methods, but is the most straightforward one to maintain/understand. |
"Overloading is evil" (https://groups.google.com/forum/#!topic/dotty-internals/T5UBRkVc8Ks). |
This is the minimal number of changes that need to be made, together with previous commits, to allow for a default Scheduler value on all Observable methods that can take a Scheduler:
I've been thinking about these methods, as well
Should we just come up with a reasonable default Scheduler for these and differ slightly from RxJava? ComputationScheduler should work in both cases. |
@jbripley thanks for the table, I think that's probably the way to go. Except for the new method names, I don't particularly like them, but can't think of any better names right now... Another idea would be to fight the problem with even more default arguments: For def repeat(count: Int = Infinity, scheduler: Scheduler = TrampolineScheduler()) (there's no integer Infinity in Scala, but we could use -1, an Option, null or another hack...) |
No particularly happy with the new method names myself. Maybe something longer and more descriptive like this is better:
When there's no natural default/sentinel value, Option is the way to go IMO: def repeat(count: Option[Int] = None, scheduler: Scheduler = TrampolineScheduler()) |
Brrr names like Then it is better to not change anything. |
Maybe I only suggested those really horrible method names so someone would feel compelled to come up with better ones :) |
As in, keep things as they are. If a refactor forces you to invent new names, it makes the API worse. |
I'm confused. Do you mean to keep the changes as currently in this PR or to not do these changes at all? |
No changes at all. This makes the API a lot worse. We will need to take a lot more time to figure this out. Sometimes an approach looks promising, but turns out to be a dead end. We have found a textbook example with this PR. |
I went again through the list of methods which have multiple overloads taking a Scheduler, i.e. those which would require renaming if we wanted to use default arguments for Schedulers. I found that they can be split into two categories:
So far, all attempts to rename these methods to avoid the conflicts resulted in ugly long COBOL-like names. I also tried to use something like a
As you can see, this post does not propose any solution. But I still have some hope that we might be able to use default arguments for default Schedulers, so I'm posting this to initiate others to think about it ;-) |
I like alt. 2. I could update this PR with those changes, and put in default schedulers for the method that didn't work properly before, if @headinthebox agrees. |
@jbripley please don't start coding before we have a complete solution. My above post only gives renamings for the method category 2), but what would you do with those listed under 1)? |
Sorry, I read through your comment a bit too quickly over lunch and misinterpreted the two groups. I'll try to think of something for group 1, but Scala doesn't give us that many options with regards to overloaded methods. A version of the SizeBound using a sealed trait will make that a bit nicer, but not by much: sealed trait Bound
case class CountBound(maxCount: Int) extends Bound
case class TimeBound(maxTime: Duration) extends Bound
case class SizeBound(maxCount: Int, maxTime: Duration) extends Bound |
Fixes #40 by removing Observable methods that also have a Scheduler parameter counterpart, by providing a default value for the Scheduler parameter.