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)
  • nebeker@programming.dev
    link
    fedilink
    English
    arrow-up
    0
    ·
    2 months 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.

    • Traister101@lemmy.today
      link
      fedilink
      arrow-up
      0
      ·
      2 months 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

        • terabyterex@lemmy.world
          link
          fedilink
          arrow-up
          0
          ·
          2 months ago

          you can also tell them java cant handle.pointers. i have worked with a lot of backend c code using c#.

          not sure about the following but:

          can you control how a struct is handled in memory in java? (had tto do this with a c# front end calling a credit card verifyling service/library written in c++)

          do they have value types?

    • Kwdg@discuss.tchncs.de
      link
      fedilink
      arrow-up
      0
      ·
      2 months ago

      It’s actually pretty similar to rust, only that rust can import multiple modules (namespaces) in one line, which is just syntax sugar, and the syntax is slightly different.

      Your example would be

      use my_projext::domain::entities;
      use my_project::api::contracts::routes::http as routes;
      
      • nebeker@programming.dev
        link
        fedilink
        English
        arrow-up
        1
        ·
        2 months ago

        Rust adds the curly brace syntax so you can import a specific subset from a module, but I can’t decide if I like that. In C# you just keep adding extra lines which take up more vertical space, but if you sort your using a alphabetically (which your IDE can do), I think you get a very readable list. In sum, Rust adds a feature that I don’t really actually like.

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