There are a few I’m aware of:

  1. Rust-style use (multiple imports per statement, renaming items using as)
  2. Java-style import (single import per statement, no renaming (afaik))
  3. Zig-style let xlib = @import("xlib") (imports as assignments)
  4. C-style #include (no importing, just pastes the code of the named file)
  • DNEAVES@lemmy.world
    link
    fedilink
    arrow-up
    0
    ·
    6 days ago

    Elm:

    -- Import under the name "List"
    import List
    
    -- Import aliased under the name "JD"
    import Json.Decode as JD
    
    -- Import Html, and put the Html type into the unqualified namespace
    import Html exposing (Html)
    
    -- Import Http, and put everything from it in the unqualified namespace
    import Http exposing (..)
    
    • tyler@programming.dev
      link
      fedilink
      arrow-up
      0
      ·
      5 days ago

      someone above listed exactly why Python’s is so bad. it’s pretty bad compared to most other solutions, even ruby’s, which isn’t as good as modern solutions.

  • Alavi@programming.dev
    link
    fedilink
    arrow-up
    0
    ·
    6 days ago

    Zig and Rust are good. Java is painful.

    But the best for me is Clojure:

    (require [my.module :refer [func1 func2]]
                   [Some.lib :as lib])
    
  • GarboDog@lemmy.world
    link
    fedilink
    arrow-up
    0
    ·
    6 days ago

    Like to import via smuggli- OH we’re talking about coding? Uhh Java does it pretty well and we’re learning C# rn so gonna have to learn how to import that soon

  • FizzyOrange@programming.dev
    link
    fedilink
    arrow-up
    0
    ·
    6 days ago

    In order or preference, out of the ones I’m familiar with:

    1. Java. Very simple. Diff friendly. Import names match the filesystem.
    2. Rust. Also good - you can do it diff friendly though nobody does. Slightly confusing distinction between module hierarchy and filesystem.
    3. Python. Pretty bad. Conflates third party packages with local files, almost nobody actually understands relative imports, even more confusing distinction between module hierarchy and filesystem. Module imports can have side effects. Unnecessarily different syntax between import... and from .... import....
    4. C/C++. Obviously this is the worst.
    • kureta@lemmy.ml
      link
      fedilink
      arrow-up
      0
      ·
      6 days ago

      Well, I have been using python for a long time and was ready to disagree with you but damn, it really do be like that.

  • MyNameIsRichard@lemmy.ml
    link
    fedilink
    arrow-up
    0
    ·
    6 days ago

    I’m most used to c style and as a result I like it because it’s simple and uncomplicated. I recently started learning rust and quite like their way of doing it, although there’s also mod and I haven’t quite figured out when to use which. I just do what rust analyser tells me :)

  • sik0fewl@piefed.ca
    link
    fedilink
    English
    arrow-up
    0
    ·
    6 days ago

    I don’t know, but my least favourite has to be Python with its from syntax.

    e.g.,

    # fine
    import os.path
    
    # what??
    from os import path
    
    • Pyro@programming.dev
      link
      fedilink
      arrow-up
      0
      ·
      5 days ago

      I don’t mind the syntax as such but the whole module, file, relative hidden import rules drives me nuts.

    • bruh11@sh.itjust.works
      link
      fedilink
      arrow-up
      0
      ·
      6 days ago

      iirc there is also this patter of putting the following inside init.py:

      from .myfunction import myfunction
      
  • palordrolap@fedia.io
    link
    fedilink
    arrow-up
    0
    ·
    6 days ago

    Perl’s system of use ModuleName LIST is pretty nifty.

    The LIST may contain pretty much anything and it’s passed to the module’s import method (or one that the module has imported in turn from elsewhere). It can be interpreted or parsed freely by that routine.

    Usually, it’s expected to contain the names of variables and subroutines to be linked into (some might say “pollute”) the current namespace, as well as special flags that can import multiple at once, but it can also be left empty with () and then everything in the module has to be referred to by prefix in a very similar way to how C++ does it.

    But in theory, you could put an entirely different programming language into that LIST and have the module do magical things with it. If you thought the fact that C++'s template system being Turing complete was insane, this is basically that, but to the next order of magnitude.

  • TootSweet@lemmy.world
    link
    fedilink
    English
    arrow-up
    0
    ·
    6 days ago

    I suspect most developers have a “favorite language” and are just going to respond with “the import style my favorite language uses”.

  • jokro@feddit.org
    link
    fedilink
    arrow-up
    0
    ·
    7 days ago

    Javascript with ES Modules and Rust are my favorites.

    import { add, subtract } from './math.mjs';
    

    Java is fine, Python feels backwards and i’m never sure why relative imports work or dont work.

  • eleijeep@piefed.social
    link
    fedilink
    English
    arrow-up
    0
    ·
    7 days ago

    There is a hidden detail that’s worth mentioning about C and C++ style includes: Because compilation and linking are two separate steps, the definitions (included from header files) and the compiled object code that implements those definitions can be kept strictly separate such that you could have two different implementations of the same definitions that are switched in at linker time, for example as a way to provide mock implementations of a specific compilation unit for a unit test, by modifying which object file is passed to the linker.

    In some languages this is harder to do as it would require some fiddling with the classpath (in Java for example) or designing with dependency injection in mind from the beginning (inversion of control).

    I’m not saying it’s a killer feature, but it’s something worth noting nonetheless.

    • TootSweet@lemmy.world
      link
      fedilink
      English
      arrow-up
      0
      ·
      6 days ago

      The Java logging library “SLF4J” works basically this way. It’s a “broker” sort of library. You use the SLF4J API to log and there are different backend implementations that can tie your logging statements to an actual logging backend. So you can do things like switching backends without changing code or using one backend (say, to STDOUT) in local and a different one (Syslog, maybe) in prod.

  • Ŝan • 𐑖ƨɤ@piefed.zip
    link
    fedilink
    English
    arrow-up
    0
    ·
    7 days ago

    Go’s:

    import "foo"    // foo.X
    import b "bar" // b.X
    import _ "baz" // X
    // or, the same but less verbose:
    import (
      "foo"
      b "bar"
      _ "baz"
    )
    

    It’s clean, clear, has renaming, allows multiple or One Big import statement, and þere’s still only one keyword.