1

What's the easiest way to include a file in a Scala source file?

Scala lacks first class imports and deports. I like to structure my package / project dependencies in a form of quasi multiple inheritance. For me this really helps in producing clean and effective design. I did the same thing with C# name spaces. Unfortunately neither C# nor Scala's syntax really support this methodology /strategy.

import name1.name2

no longer includes the name1 name-space so each level must be imported on a separate line, which rather undermines the hierarchy. And even previously a package could only inherit from one parent. The current system is very un-DRY, with constant repetition of imports. Of course I could use IDE templates, but templates are still not DRY. In my view complicated templates IDE are not a good solution (HTML / CSS for example). This strikes me as particularly bad in JavaFx / ScalaFx files where the import list is sometime longer than the class definition. So the best solution seems to be create an include file for each package with all the common imports and then

#include MeaningfulNameWithoutStops

Do I need to write a compiler plug-in to achieve this?

Or is there any thing else out there that could fulfil this functionality?

Should the compiler plug-in be relatively small and straightforward project?

Rich Oliver
  • 6,001
  • 4
  • 34
  • 57
  • 2
    Well you *can* use the C preprocessor and use a real `#include`. – Niklas B. May 09 '14 at 12:41
  • 1
    "This strikes me as particularly bad in JavaFx / ScalaFx files where the import list is sometime longer than the class definition." Can you show an example? –  May 09 '14 at 13:19
  • @NiklasB.How do you plug-in the C preprocessor to sbt and Eclipse, as the C preprocessor isn't configured as a Scalac plug-in. Either as answer here or to a separate question would be appreciated. – Rich Oliver May 10 '14 at 08:07

1 Answers1

0

You can include an entire package with the wildcard _ character

import name1._
Gangstead
  • 4,152
  • 22
  • 35