#Is this statement `const UI = @import("ui").UI;` a bad idea?

1 messages · Page 1 of 1 (latest)

nova dragon
#

What's the standard practice? Should I even use an external module?

nova dragon
#

Wait so I had a dumb idea, I can just move the whole inside of the struct as the module...

#

But doesn't that mean I can have only 1 instance of ui?

#

Is that not how this works hahah.

nova dragon
#

😢

raven hull
#

import returns a struct representing the contents of the file. (Files are structs in Zig.)
But no - that doesn't mean you only get one instance -- it returns the struct type - so you can make instances from that, just like any other type.

I will note though that you cannot make a file be a union, or things like a extern struct, for example.

#

I don't think there's anything inherently wrong with const UI = @import("ui.zig").UI; though.

#

Taking advantage of the file-as-struct thing when importing basically turns a type into a single file.
But that's generally not what I want when I'm writing code; I want modules that organise based on what the code is about - not what type it is.

delicate ridge
#

I love discussing unimportant things like naming conventions, so I am required to tell you that it should be called Ui instead

raven hull
delicate ridge
#

no you openissue

swift axle