package.elm-lang.org icon indicating copy to clipboard operation
package.elm-lang.org copied to clipboard

The website doesn't explain how to import a package

Open lucamug opened this issue 4 years ago • 3 comments

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

lucamug avatar Apr 12 '20 00:04 lucamug

+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?

Kurren123 avatar May 13 '20 10:05 Kurren123

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 (..)).

  • Maybe this could point to an updated version of https://github.com/elm-lang/elm-package/blob/72c69fcdc5b21cb9035f081dbbc79db4401fe817/README.md, with a new section about import.
  • Or maybe this could point to the Elm guide section about installing packages, that would be completed with a basic explanation of import: https://guide.elm-lang.org/install/elm.html#elm-install

rlefevre avatar May 13 '20 12:05 rlefevre

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

lucamug avatar Feb 28 '21 14:02 lucamug