First, apologies for having hijacked the Dotty-announce thread.
I have no big stakes in this, but given that the given
syntax has now - correct me if I’m wrong - mostly reverted to match the current implicit
syntax, i.e. no infix keyword, mandatory parentheses: Is there any gain from renaming implicit
to given
at all?
Here are my arguments:
- both
given
andimplicit
capture the same amount of intuitive concept - you have to explain the concept to newcomers in both cases
-
implicit
has been around for very long time, it’s has proven to be an elegant way of writing things -
implicit
/implicitly
is a very easy to grasp pair, whereasgiven
/summon
intuitively has very little to do with each other - I give it to
given
that it saves me some characters typing. Is that enough to have to rewrite a lot of things?
I really liked the infix syntax, here given
was making indeed sense. But now, compare:
given {
def (xs: List[T]) second[T] = xs.tail.head
}
versus
implicit {
def (xs: List[T]) second[T] = xs.tail.head
}
and
def max[T](x: T, y: T)(given ord: Ord[T]): T =
if (ord.compare(x, y) < 0) y else x
max(2, 3)(given IntOrd)
versus
def max[T](x: T, y: T)(implicit ord: Ord[T]): T =
if (ord.compare(x, y) < 0) y else x
max(2, 3)(implicit IntOrd)
and
given Position = enclosingTree.position
versus
implicit Position = enclosingTree.position
I think the implicit
variant is at least as clear. By the way, it’s still ImplicitFunctionN
not GivenFunctionN
, perhaps because the latter is really less obvious.
best, .h.h.