Skip to content

The README.md is unclear about imports #115

@VincentPikand

Description

@VincentPikand

This part of the README

Screenshot 2023-06-13 at 11 42 23

My problem

I don't understand how using is more explicit and clearer than import.

Consider this example:
Imagine this code is part of some bigger library and somebody forgot to add the prefix LinearAlgebra to eigvals, which I believe is the intended style because then the namespace is clear.

julia> import LinearAlgebra
       x = [1 0 0; 0 1 0; 0 0 1]
       print(eigvals(x))
ERROR: UndefVarError: eigvals not defined

We get a nice error, because eigvals is not in our namespace. However, this code is not following the Blue style guide because of

Prefer the use of using over import to ensure that extension of a function is always explicit and on purpose

Writing this using the blue style guide we don't get an error, so mistakes like this can easily go unnoticed.

julia> using LinearAlgebra
       x = [1 0 0; 0 1 0; 0 0 1]
       print(eigvals(x))
[1.0, 1.0, 1.0]

also,

Note: Prefer the use of imports with explicit declarations when writing packages.

what imports, imports as in import or imports in general? An example would make it clearer.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions