I would like to bring up the question whether to keep wildcard imports in future Scala versions (dotty).
This problem first came to me while working on scripting. I wanted to use the Scala compiler from a restricted environment (Java web start, servlet engine, Android, etc.) In such context, often you do not have access permission to library jars, so you cannot list all classes present in some package for instance. A consequence is that the compiler cannot make sense of wildcard imports
This was also causing problems with the reflect Toolbox, but macros were reworked in Dotty not to allow such things (and rightly so).
However, the issue was brought back recently in the rework of implicits:
In fact, I’d go a step further and say wildcard imports:
Are themselves a code smell, implicits or not
As it turns out, big piles of imports are only a problem for implicits, as normal “flat” imports are dealt with by IDEs these days (and they are best practice, for readability and understandability of code).
Why not put the effort on implicit imports automation in IDEs, instead of devising such complicated wildcard imports as is currently the case:
I ask the question (and yes, there is the problem of anonymous implied/delegate/given instances, I do not have an answer for these now, maybe naming them should be mandatory if they are to be imported).
Any thougths ?
Edit: There is also the problem of “implicit” wildcard imports, in the sense that you do not have to import them explicitly. There are 3 of them:
import java.lang._ import scala._ import Predef._
These might be easy to do without, or not, the question is open.
Edit2: We could also consider that all classes in the current package are also wildcard imported, as in:
On a scripting point of view, this might not be a problem, as we can suppose that all classes in the current package are in the source classpath, that is, with no permission restriction. But this brings up the case where we have nested packages, as in:
package foo package bar
, which translates to:
package foo.bar import foo._
I have never been comfortable with this construct, which introduce too much complexity in my opinion, in particular for beginners. So I guess my proposal is also to get rid of nested packages.