-
Notifications
You must be signed in to change notification settings - Fork 219
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 style and modularisation #2288
Comments
This might be overly restrictive. A more moderate proposal is that each subfolder under
I am probably too familiar with the code to say anything useful. But |
I don't have super-strong opionions regarding exactly where we define the different namespaces, but I very much agree with not doing this 👍 |
That could be a good middle ground if one-module-one-file is a bit too much. Happy to be flexible with this, but I do think more submodules would help structure our namespaces and provide some clear interfaces, defining what is an implementation detail and what is a key part of functionality. This would also help readability of the code, to understand what are the "external facing" functions of some subpart of a package. To take an example, in DynamicPPL I would make everything related to VarInfo a module. Could be that VarInfo, SimpleVarInfo, and AbstractVarInfo are also all their own modules, or could be that they are all together, but I think there's a natural interface between those types and the rest of DynamicPPL, and making the code structure reflect that separation of concerns would, in my opinion, clarify the code.
Yeah, these help, language servers help, but I do still find myself grepping the code to find where things are defined. Also, when browsing code on GitHub this comes up a lot. |
Might be helpful: https://github.com/ericphanson/ExplicitImports.jl |
Interesting. Seems like not using |
Yes, my impression is that explicit imports have been the (inofficial) recommendation for quite a while. I also think that making every file its own module is too much. The new My general approach to clearly mark where functions etc are defined is to not import anything beyond the package module (ie only |
Okay, so broad support for explicit imports, some support for more submodules, but maybe not quite to the one-file-one-module level. What are the reasons why people would like to not go to one-file-one-module? Is it just the verbosity of having to add more imports at the beginning of each file? That would bring in some boilerplate, but reason I'd be willing to pay that price is that I really enjoy the cleanness and simplicity of the guarantee that any name you encounter in a file is either 1) in Base, 2) defined in this file, or 3) explicitly imported at the top of file. You could not ever have something in your namespace that isn't made explicitly clear how it enters that namespace. |
I'm against one module per file because modules are not designed and intended to be used in this way. Files are intentionally distinct from modules. There also seems to be a general sentiment in the community that many submodules seems to indicate that you should split your package into several packages.
That's also the case if you don't import anything. Arguably, also for some functions such as |
I see the intent of modules to be namespace management, which is very much what a one module per file policy would be about. I can imagine there are some cases where one wants to
Sorry, I don't understand what you mean here. The cases that bother me are things like these: include("a.jl")
include("b.jl")
include("c.jl")
include("d.jl")
include("e.jl")
include("f.jl")
include("g.jl") Say I'm reading Note also that probably files |
Often when reading Turing.jl code (and many other Julia projects) I'm struck by how hard it is to see where names (functions, variables, types) are defined. There are two parts to this problem:
using X
syntax brings things into a namespace without explicitly naming them.include
d in one module means that things defined in one file are in scope in another, without either file explicitly referencing the other.To counter this issue, I'd propose two conventions:
using X: a, b, c
,using X: X
,import X: a, b, c
, orimport X
.I wouldn't be surprised if 2. turned out to be a bit overly strict in some cases, and I'm happy to have some flexibility there. Maybe 2. should just say "use more submodules".
I don't propose anyone goes and writes a single massive PR for this. Rather I'm asking for comments on this as a style convention. If there's support for this, I'd slowly start applying the new conventions as I edit code.
I raise this as a Turing.jl issue, but I'd eventually like for this to apply to all of TuringLang (and preferably the rest of the universe too).
Thoughts?
The text was updated successfully, but these errors were encountered: