-
Notifications
You must be signed in to change notification settings - Fork 1k
New packages and imports tour #714
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
fb85502
to
f336253
Compare
This file needs a |
import users._ // import everything from the users package | ||
import users.User // import the class User | ||
import users.{User, UserPreferences} // Only imports selected members | ||
import users.{UserPreferences => UPrefs} // import and rename for convenience |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should also mention import hiding, like import foo.bar. { Qux => _, _ }
which imports everything except Qux
.
``` | ||
|
||
|
||
Note: The `scala` and `java.lang` packages as well as `object Predef` are imported by default. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This deserves more detail and should be more explicit. What exactly are the default imports? How do explicit imports and import hiding interact with this? We have not mentioned importing symbols from things other than packages, so import scala.Predef._
will not make sense at this point.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also what compiler options affect these defaults?
|
||
class User | ||
``` | ||
One convention is to name the package the same as the directory containing the Scala file. The directory structure of an sbt project for `package users` might look like this: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should probably mention that scala doesn't care about file layout at all. This is just a convention. However some tools might care (I think IntelliJ does).
import users.{UserPreferences => UPrefs} // import and rename for convenience | ||
``` | ||
|
||
One way in which Scala is different from Java is that imports can be used anywhere: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing:
- relative imports
(given: foo.bar.buz)
import foo._
import bar.buz._
or
import foo._, bar.buz._
- package object
f336253
to
c758f36
Compare
@heathermiller ready to merge |
I think this probably still has some further evolution ahead of it, but it seems mergeable to me as it stands. Merging! |
oh, this needs fixing up for the new directory structure... |
cee4a66 moves it into place |
argh, now that we have html-proofer running, it shows:
|
I'll fix it in #984 |
No description provided.