Is the exporting feature really necessary?

As far as I see, if

class A
{
export package.element;
}

creates a new member element in class A, then it suffices to only have import package.element.

If it is some kind of delegation, then it suffice to use an extension function:

def (a: A) element: SomeType = package.element;

or maybe some kind of in-place variant in classes in case of access restrictions:

class A
{
extension element:SomeType=package.element;
}

It’s necessary precisely because such forwarding functions are tedious to write and do not update automatically when their targets change.

For example, suppose I want to make my own Predef and put my most commonly used libraries there. In Scala 2 this is a huge, truly arduous task. In Scala 3 it’s a few lines:

package myprelude

export lib1._
export lib2._
export lib3._

IMHO this is the best new feature in Dotty, addressing a long-time concern. The only thing better would be to also have Kotlin-esque scope injection to go with exports.

3 Likes

Yes, it is. Especially now that package object is dropped.

3 Likes