After some experience with the new import given feature I propose a syntax change for wildcard imports.
Instead of
import p.{given _}
write
import p.given
The same applies for wildcard given imports in braces: given _
is contracted to just given
. Given-by-type imports remain unaffected: It’s still
import p.{given T}
for those.
The rationale is that we should not make it needlessly hard to write wildcard given imports. The additional underscore after a given
is not needed for disambiguation and clutters the code.
The change has been implemented in Change wildcard given selectors by odersky · Pull Request #9949 · lampepfl/dotty · GitHub.
7 Likes
For completeness,
import p.{given ?}
which is accepted but doesn’t seem to mean anything.
Edit: asked and answered: https://github.com/lampepfl/dotty/issues/8696 except for the part where the syntax isn’t rejected.
The syntax will be rejected once #9949 is merged.
2 Likes
Could you please remind me why import given ...
syntax was rejected previously?
The reason i’m asking is imports ergonomics. I find current syntax is quite hard to manage if file has multiple imports with long packages (which is quite common for enterprise applications) and if formatters use alphabetical sorting it became messy with given in different places.
If we had keyword after import it would be easy to order and group given
imports together, like:
import cats.data._
import com.something._
import io.circe._
import given cats.implicits._
import given io.circe.syntax._
8 Likes
The new syntax works better with type bounds.
1 Like