Packages are oftentimes used as ways to break down single code files. This can improve code organization, as it
- avoids long files.
- reduces the scope of top-level import statements.
- allows definitions to be grouped (and the latter to be named).
- reduces artificial sequentialization of definitions, which conceptually form an unordered set.
However, packages are currently treated quite differently from files by Scala, as, in general, they can span multiple directories, and do not form an atomic incremental compilation unit. This prevents
sealed and wildcard exports from working at the package level.
Could a more restricted new type of package be introduced to Scala, to be treated by the compiler like a single file?
Such closed leaf packages could either be declared explicitly, or perhaps even be inferred by the compiler (though the latter might not be practical due to incremental compilation).
- Single directory
- Same name as directory
- No sub-packages
- Bounded size