I don’t love the new package usage. It’s one more thing for new Scala programmers to learn. _root_.foo.bar.baz is actually a pretty good solution in my mind, except by avoiding taking a new reserved word it changes root.foo.bar.baz (which I don’t think many people would mind) with _root_.foo.bar.baz which technically is pretty similar but aesthetically I think just puts many people off and won’t be used in a widespread manner. It’s not like anyone actually finds it confusing, they just find it ugly.
I can already see the conversations…
New user of import package foo.bar: “What does import package mean?”
Me: “It means import from root”
New user of import package: “Well why didn’t they just say import root then?”
I can see a couple of alternatives that I haven’t noticed being proposed yet so I’ll toss them in the ring.
-
Could we take root as a keyword, even if only following import?
Import root.foo.bar.baz -
What about an alternative but already widely known syntax that is new to imports but immediately familiar to most developers while deprecating the old style?
Import /foo/bar/baz (import from root)
Import bar/baz (import relative)
Import foo.bar.baz (import old style) -
Make root imports the default and add a special indicator for relative imports, (maybe hide it behind a compiler flag, I think I could come up with a scalafix for old code to make it compatible once the flag is set). The thinking here is that if we actually want root imports to be the common case, with no syntax tax, then add the tax onto the relative imports.
Import foo.bar.baz (this is the same as _root_.foo.bar.baz)
Import ~.bar.baz (relative import from whatever is in scope) I’m not attached to the tilde here, the idea is to make the less preferred syntax uglier, instead of making the preferred usage uglier as import package or _root_ do.