Skip to content
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

The website doesn't explain how to import a package #334

Open
lucamug opened this issue Apr 12, 2020 · 3 comments
Open

The website doesn't explain how to import a package #334

lucamug opened this issue Apr 12, 2020 · 3 comments

Comments

@lucamug
Copy link

lucamug commented Apr 12, 2020

I have seen beginners struggling in understanding how to import a package, especially because there is no enforced consistency in naming.

For example

elm/html              -> import Html
evancz/elm-playground -> import Playground
mdgriffith/elm-ui     -> import Element

Such information now is available in the right side column but it is not explicit:

Screen Shot 2020-04-12 at 8 45 32

This extra info could be added in the already present "About" page (https://package.elm-lang.org/packages/mdgriffith/elm-ui/latest/about):

Screen Shot 2020-04-12 at 8 50 00

@Kurren123
Copy link

Kurren123 commented May 13, 2020

+1 I struggled with this quite a bit when starting off. Only issue I'm thinking is that if you have something like

import Element
import Element.Background
import Element.Border

Is there a risk that beginners will just copy the whole thing into their module when they only need import eg Element?

@rlefevre
Copy link
Member

rlefevre commented May 13, 2020

I think the risk is high that beginners will copy the whole thing indeed, and because a lot of code examples assume exposing (..), particularly core libraries, this would not help much anyway.

Also, with regard to the examples above, the 4th line of elm/html documentation shows an import example:
https://package.elm-lang.org/packages/elm/html/latest/

Idem for elm-ui in the example just after the introduction:
https://package.elm-lang.org/packages/mdgriffith/elm-ui/latest/

If this did not help, why adding them again in the About page would?

In my opinion, they are better illustrated by code examples that include the import directives to show why the names are qualified, or not, or with an alias.

But to explain them at first, I think it would be better to fix the "Using Packages" link and explain how to install and import in this documentation (including as and exposing (..)).

@lucamug
Copy link
Author

lucamug commented Feb 28, 2021

Yes, sometime package authors add example that also include the imports, but it is not always the case, so I think an example generated automatically could be a safer approach.

Having begineers copying all the imports, even if not necessary, seems to me a minor issue compared to have them struggling in making their code to work. At least the code is running. They will eventually learn and most IDE now have warnings for unused imports.

About explaing about importing modules, this could be a good target: https://elm-lang.org/docs/syntax#modules

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