-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
import function: relative to package root, or relative to current file, or both? #216
Comments
I brought this up on IRC a couple of days ago. In C, I'm either including an <external_dependency.h> or an "internal_dependency.h".
However, this is just the way I "namespace" my projects in C. It forces me to pay attention to dependencies and go through sanity checks when turning parts of my code into standalone "modules". Status quo is fine, and might keep things sane once the build system is fully fleshed out. Potential cons include increased effort when moving around source files with very complicated dependency trees, and there's a little voice inside me saying your "reproducible builds" objective might be easier if you disallow relative imports. As for how to do it if you so choose, I very much like the Node way of doing it: relative if import string begins with ./ or ../. This way we keep the single import function |
Argument in favor of paths relative to current file: if you drop files from one project into another, they will work unmodified. We'll expose both package root and source file name in a compile variable, so technically regardless of the default, you can get the other behavior: Example: |
Is |
but that example wont work regardless because |
further stuff should be taken to https://github.com/ziglang/zig/wiki/Community |
Currently,
@import("foo.zig")
looks for foo.zig relative to the package root.Another way to do it would be to have it look relative to the directory of the file doing the import.
Another way would be to have a rule like "if it starts with ./ or ../ then look relative to the directory of the file doing the import".
Yet another way be to have 2 different import builtin functions for each of these behaviors.
Which way is best? I'm not sure. Status quo seems to work fine for the use cases I've thought of. It's closer to how it works in C with
#include
statements. But being closer to C isn't necessarily better or worse in this case.Having it work only one way instead of two ways would be preferable, since that aligns with the design goal of orthogonality (limit programmer choices in order for code to generally look and feel the same).
Anyone have example use cases to inform how we can choose which way is best?
The text was updated successfully, but these errors were encountered: