I am curious to see how others use @import() with regard to code style. This is a purely subjective matter - unless you’re doing something really weird, I guess - so please forgive the noise.
I used to import modules such that symbols would be referenced at a maximum depth of 1 namespace. For example, when using std.debug.print, I would import std.debug as debug and use it directly.
const std = @import("std");
const debug = std.debug;
pub fn main() void {
debug.print("Hello, world!\n", .{});
}
After a while, I decided that I could be more explicit in by referring to each namespace absolutely. However, this has some code style side-effects, such as making nested, long-lined conditional statements look a bit janky.
const std = @import("std");
pub fn main() void {
std.debug.print("Hello, world!\n", .{});
}
Currently, I still refer to the absolute namespace and additionally put my imports at the bottom of the file.
pub fn main() void {
std.debug.print("Hello, world!\n", .{});
}
const std = @import("std");