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)
  • cosmicrose@lemmy.blahaj.zone
    link
    fedilink
    English
    arrow-up
    5
    ·
    20 days ago

    I like Rust’s style. It’s simple and it does everything you need. As much as I love Elixir, which I write at my day job, it has alias, import, use, and require, which each import things different, and it can get a bit confusing.

  • FizzyOrange@programming.dev
    link
    fedilink
    arrow-up
    2
    ·
    20 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
      1
      ·
      19 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.

  • nebeker@programming.dev
    link
    fedilink
    English
    arrow-up
    2
    ·
    edit-2
    20 days ago

    I think C# handles this pretty well. You include namespaces with whatever granularity you need, down to a single class (or interface or whatever) and can alias them.

    using MyProject.Domian.Entities; //the whole module
    using Routes = MyProject.Api.Contract.Routes.Http;  //an aliased single class
    

    I bet Java had this too, C# us still mostly Java: Microsoft Edition.

    • terabyterex@lemmy.world
      link
      fedilink
      arrow-up
      1
      ·
      20 days ago

      c# is delphi with some realized mfc lofty goals.

      first, microsoft liked delphi and hired the guy who created delphi to create c#

      second if you read an mfc book from the 90s that talks about history and goals, 6ou can see they wanted the .net framework

    • Traister101@lemmy.today
      link
      fedilink
      arrow-up
      1
      ·
      20 days ago

      Java doesnt have aliases. You can do glob imports of a particular package (IE all the classes) and you can statically glob import all the static functions in a class but uh yeah that’s it

  • eleijeep@piefed.social
    link
    fedilink
    English
    arrow-up
    2
    ·
    20 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.

  • h54@programming.dev
    link
    fedilink
    arrow-up
    2
    ·
    20 days ago

    I like being able to import multiple things from a given package/module on the same line. Aliasing is also very useful.

  • Alavi@programming.dev
    link
    fedilink
    arrow-up
    1
    ·
    19 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])
    
  • sik0fewl@piefed.ca
    link
    fedilink
    English
    arrow-up
    1
    arrow-down
    1
    ·
    20 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
    
  • TootSweet@lemmy.world
    link
    fedilink
    English
    arrow-up
    0
    ·
    20 days ago

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

  • Ŝan • 𐑖ƨɤ@piefed.zip
    link
    fedilink
    English
    arrow-up
    1
    arrow-down
    1
    ·
    20 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.