-
Notifications
You must be signed in to change notification settings - Fork 18
Proposal: Structure of extension methods #46
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
Comments
I think there has been previous discussion about whether to have a single I would like to make one counter-proposal and ask one clarifying question.
The reasoning behind my proposal to call the value classes
Do you mean that the class itself or the constructor should be I like this proposal a lot, and I think it will help a lot with maintainability. |
One small thing I'm curious about: do you think |
I just did a quick experiment and it seems that if the implicit conversion has the same name as the value class, even if the code compiles it never finds the extension methods. But the first letter of the
The class itself, which should automatically make the constructor also private AFAIK.
Since both value classes will not be companions of each other, I do not see any benefit on having them on the same file. Vote with: 👍 to keep the extension methods of the companion object on its own file.
That was the idea :) |
That would be very dangerous for case insensitive file systems, for example on Windows. It might crash on such systems. |
@sjrd not sure if I am missing something but I was talking about the name of the |
In general on Windows you can't have a class and an object whose names differ only in case. The object will also generate a class so it will clash with the class. The class may also generate an object (notably it will if it is a value class), which will also clash. If it's a def, there's a chance it would work, because maybe the def doesn't clash with the generated object because it doesn't need a file. But I wouldn't take that chance. |
Effectively the compiler is way more complex than what I thought. That is probably a good reason why cats uses a different name for the class and the def (or it may have been just a causality). |
I haven't read all the words yet, but I'm wondering why there is an embrace of Using package objects feels so 2016. I guess that would be pre-election 2016, from a US perspective, and definitely pre-October-surprise. |
can you have an |
Is it desirable to have a OK I just read the top of this ticket, after previously getting scared off by the MUST legalese. I don't see the reason to avoid leveraging implicit classes and hand-implement the def conversions. I would vote for "localized" name space such as Otherwise I might put some |
Because implicit classes can't be top-level so we can not just define them in their own files.
|
@NthPortal just to be sure I just did this quick experiment with a local publish of #23 // Welcome to the Ammonite Repl 2.3.8 (Scala 2.13.3 Java 11.0.9)
@ import $ivy.`org.scala-lang.modules::scalalibrarynext:0.0.1+27-8f9fd9cb-SNAPSHOT`
// import $ivy.$
@ import scala.collection.next._
// import scala.collection.next._
@ "Hello World Goodbye World".split(' ').iterator.groupMapReduce(identity)(_ => 1)(_ + _)
// res: Map[String, Int] = Map("Hello" -> 1, "World" -> 2, "Goodbye" -> 1) 🙂 Also, if I ask Ammonite what can I import from |
I'm largely in favour of this proposal, though I'm not a huge fan of the value classes being private—that seems confusing and unintuitive to me, regardless of it working (possibly a bug?). despite saying this, I don't think it's worth holding the proposal up over that, and my feelings on it are not super strong. I feel much more strongly about getting this finalised and getting a few PRs merged soon (although we can also merge PRs without waiting and then just tweak the code later once we finalise this). |
I propose that we don't wait on finalizing this and #24 to merge PRs, and we can just refactor the library once we've decided on those. |
This proposal is based upon #24 for naming and package structure (here we are assuming that both proposals were chosen, at least partially) and further specifies where should the extension methods be placed.
This proposal has three end goals:
3.1
in the future.next
subpackage (as required by Proposals for naming and package structure #24).As such, I propose the following:
Next<Name>Extensions
placed in anext
subpackage.final
&private[next]
private
.Next<Name>Extensions.scala
.next
subdirectory.Name
intoNext<Name>Extensions
MUST be declared in the package objectnext
; and MUST be namedscalaNextSyntaxFor<Name>
.Example:
One open discussion for this proposal would be:
next
package for all extensions:scala.next._
next
packages for each package of the stdlib:scala.collection.next._
,scala.collection.immutable.next._
, etc.Vote with:
In favour of this proposal going with option 1. (👍)
In favour of this proposal going with option 2. (🚀)
Completely against this proposal. (👎)
The text was updated successfully, but these errors were encountered: