Scala Packages gives an overview of what packages in Scala are.
On the surface, they are a slightly more flexible version of Java’s imports:
You can also import packages anywhere you want, and those imports will be applied to the given scope. This lets you keep code a bit cleaner by reducing the scope of available symbols and classes to only the most minimal.
However, this doesn’t really touch on some of the subtleties of how Scala treats packages.
My Thoughts on this Feature
I’m not a fan of imports and, while Scala breaks the “packages are just directories on the filesystem” concept, I think a higher level abstract should’ve been created. I’d love to say something like
2.8 adds some great new features to PackageObjects, however we still don’t have my dream of treating packages as higher-level modules with versions like above. Ah well :)
Scala also relies much more heavily on so-called “static imports” to make the syntax more compact (specifically with ImplicitMethods). I do not like this in Java, since it can make it hard to know the source of code, but can be very powerful for API designers (and isn’t much more egregious than some of the Rubyisms that go into creating DSLs).
Last Updated 07/19/2010 at 12:16:53 PM by davecblog comments powered by Disqus
Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License.