logoalt Hacker News

perlgeeklast Sunday at 8:31 PM5 repliesview on HN

I like 99% of this, and the thing I don't like is in the very first line of the example:

> import abs, epsilon from math

IMHO it's wrong to put the imported symbols first, because the same symbol could come from two different libraries and mean different things. So the library name is pretty important, and putting it last (and burying it after a potentially long list of imported symbols) just feels wrong.

I get that it has a more natural-language vibe this way, but put there's a really good reason that most of the languages I know that put the package/module name first:

    import packageName.member; // java
    from package import symbol; # python
    use Module 'symbol'; # perl
    
With Typescript being the notable exception:

    import { pi as π } from "./maths.js";t

Replies

jasonjmcgheelast Sunday at 9:34 PM

Also autocomplete.

Though I almost never manually type out imports manually anymore.

bbkanelast Sunday at 9:30 PM

I really like the way Elm does it, from "wide" (package) to "narrow" (symbol). I suspect this also helps language server implementation.

See https://guide.elm-lang.org/webapps/modules (scroll down to "Using Modules") for examples

beariishlast Sunday at 8:43 PM

Do you think approaching the way typescript does it for Bolt is a reasonable compromise here? Bolt already supports full-module renames like

    import math as not_math
So supporting something along the lines of

    import abs as absolute, sqrt as square_root from math
Would be farily simple to accomplish.
show 3 replies
vhodgeslast Sunday at 10:54 PM

According to the Programming Guide, it supports aliases for imports

"In case of conflict or convenience, you can give modules an alias as well."

Tokumei-no-hitolast Monday at 3:51 AM

can't the compiler process it in reverse?

show 1 reply