Skip to content

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

Merged
merged 1 commit into from
Jan 9, 2018

Conversation

travissarles
Copy link
Contributor

No description provided.

@tpolecat
Copy link

This file needs a .md suffix.

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

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.

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.

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:

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:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing:

  1. relative imports

(given: foo.bar.buz)

import foo._
import bar.buz._

or

import foo._, bar.buz._
  1. package object

@travissarles
Copy link
Contributor Author

@heathermiller ready to merge

@travissarles travissarles mentioned this pull request Mar 17, 2017
33 tasks
@SethTisue
Copy link
Member

I think this probably still has some further evolution ahead of it, but it seems mergeable to me as it stands. Merging!

@SethTisue SethTisue merged commit aeed23c into scala:master Jan 9, 2018
@SethTisue
Copy link
Member

oh, this needs fixing up for the new directory structure...

@SethTisue
Copy link
Member

cee4a66 moves it into place

@SethTisue
Copy link
Member

SethTisue commented Jan 10, 2018

argh, now that we have html-proofer running, it shows:

- ./_site/tour/packages-and-imports.html
  *  internally linking to /ba/tour/packages-and-imports.html, which does not exist (line 594)
     <a href="/ba/tour/packages-and-imports.html" class="lang">Bosanski</a>
  *  internally linking to /es/tour/packages-and-imports.html, which does not exist (line 598)
     <a href="/es/tour/packages-and-imports.html" class="lang">Español</a>
  *  internally linking to /ko/tour/packages-and-imports.html, which does not exist (line 602)
     <a href="/ko/tour/packages-and-imports.html" class="lang">한국어</a>
  *  internally linking to /pl/tour/packages-and-imports.html, which does not exist (line 610)
     <a href="/pl/tour/packages-and-imports.html" class="lang">Polski</a>
  *  internally linking to /pt-br/tour/packages-and-imports.html, which does not exist (line 606)
     <a href="/pt-br/tour/packages-and-imports.html" class="lang">Português (Brasil)</a>
htmlproofer 3.7.5 | Error:  HTML-Proofer found 5 failures!

@SethTisue
Copy link
Member

I'll fix it in #984

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants