1

will chossing what classes I want from package will speed up compiling process ? If for example in package me.test I have 50 classess, and I just need two of them and I will do :

 import me.test.{ classOne, classTwo} 

instead of

 import me.test._

? Thanks

Peter Lawrey
  • 525,659
  • 79
  • 751
  • 1,130
daaatz
  • 394
  • 1
  • 2
  • 14
  • 1
    Removing `[java]` as you don't appear to want the answer about Java. – Peter Lawrey Oct 14 '13 at 11:14
  • possible duplicate of [Is wildcard import bad in Scala with respect to incremental compilation?](http://stackoverflow.com/questions/11291772/is-wildcard-import-bad-in-scala-with-respect-to-incremental-compilation) – om-nom-nom Oct 14 '13 at 11:17

2 Answers2

9

While the performance impact is negligible, here are a few things that happen:

  • Code size grows, number of classes in a package will grow.
  • You won't know where Foo comes from. This if very often a problem. Eclipse is slow with really large projects.
  • Open declaration is only available for files fetched in the EclipseKeys.withSource phase of the SBT plugin. A lot of libraries DON'T have it.

A few things from the Twitter Scala Style Guideline that have come very handy in practice:

  • Sort imports alphabetically, they are a lot easier to follow visually.
  • Only use a wildcard import pkg._ for more than 6 classes imported.
  • Use the import pck.{ Class1, Obj1 } layout for up to 6 classes.
  • Use multi-row imports for clarity
om-nom-nom
  • 62,329
  • 13
  • 183
  • 228
flavian
  • 28,161
  • 11
  • 65
  • 105
1

I don't think that it will make a significant difference for compilation speed.

In my opinion you should base that decision on what you want to communicate with that import.

  • Do you want to use the whole package? Use import me.test._.
  • Do you want to cherry-pick only some parts of the package? Use import me.test.{ ClassOne, classTwo }.
tehlexx
  • 2,821
  • 16
  • 29