Heads up: Proposal for an `export` keyword

Mark "Justin" Waks
2 min readMar 26, 2019

--

From the Dotty News Desk: Martin has just submitted a PR for perhaps the longest-requested feature in Scala: an export keyword, complementing the import one. For the details, I refer you to the documentation in the PR.

The tl;dr is that many folks have long been hoping for export as a way to say more precisely and flexibly “this is what gets exposed by this class/object/package”, including stuff that is defined elsewhere. Push finally came to shove with the removal of package objects in Scala 3, which eliminates a common idiom of organizing a package’s available imports by having the package object inherit from various objects in the package.

This closes that gap in what looks to be a much more elegant way: you can simply put export statements at the top of level of a file (thus, in the package proper), exposing the stuff you want.

Assuming that you can have exports scattered through various files in the package, this implies that you’ll be able to control the visibility of the package contents exactly as desired without needing to centralize everything through a single package object file.

It also makes it easy to create an import-centric package, that simply pulls in a bunch of components from various places and makes them available as a simple import foo._. (This should be great for folks who like to put all of a library’s guts in sub-packages, and just use the top package as the import target.)

As usual, note that this is Very, Very, Very Preliminary — a brand-new PR, not yet debugged, much less formally debated as a possible Scala 3 feature. But assuming no critical problems are found, this one looks like a big win, and my fingers are crossed that it works out…

Edited: there is now an open discussion for this proposed feature.

--

--

Mark "Justin" Waks
Mark "Justin" Waks

Written by Mark "Justin" Waks

Lifelong programmer and software architect, specializing in online social tools and (nowadays) Scala. Architect of Querki (“leading the small data revolution”).

No responses yet