Skip to content
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

Add python-like import statements #54147

Open
isentropic opened this issue Apr 19, 2024 · 2 comments
Open

Add python-like import statements #54147

isentropic opened this issue Apr 19, 2024 · 2 comments
Labels
design Design of APIs or of the language itself feature Indicates new feature / enhancement requests modules

Comments

@isentropic
Copy link

isentropic commented Apr 19, 2024

Just a suggestion from reading lots of posts about usages of julia and how things are getting out of hand when dealing with large projects. I suggest adding a new import statement as:

OtherModule = moduleimport("otherfile.jl") # as opposed to normal including it would first wrap the file in a module and the load the namespace 
# Syntax like "moduleimport("otherfile.jl") as Othermodule" could work too

# Now the stuff from the "otherfile.jl" is not verbatim included but wrapped in a module same as python does

Othermodule.function1(x)
Othermodule.function2(x)

# It is obvious for people from other languages, and perhaps could be helpful for lspless codebrowsing.

Now, instead of this being a package or a macro, wouldn't this kind of syntax be a good practice for long-term for large project development where people don't wanna wanna wrap every file in a module manually:

module Othermodule
    include("otherfile.jl") # people either have to add module...end inside
end
using .Othermodule: function1, function2

vs having one-liner import at the top of the file (same like python)

using Package1, Package2
moduleimport("otherfile.jl"): function1, function2
moduleimport("otherfile2.jl"): function3 as f3, function4 as f4

The precise syntax is not of importance, but this is rather an idea how to promote a workflow that suits large codebases better. I wish if such syntax existed in core julia then lsp and other code solution could have a much easier time of discerning what is what and where is it coming form without relying on lsp too much.

This might be a simple macro or what not, but the purpose here is to promote such style of development in general without relying on 3rd party packages. This might touch upon issues like #4600 #39235 #42080 or merging import and using keywords. Feel free to delete this issue in case this is a dup or something like that.

@nsajko
Copy link
Contributor

nsajko commented Apr 19, 2024

Pretty sure this was already discussed ad nauseam, and the conclusion is that such functionality could/should live in a user package (some examples exist). Personally, I much prefer having each Julia source file start with module explicitly.

@nsajko nsajko added feature Indicates new feature / enhancement requests design Design of APIs or of the language itself modules labels Apr 19, 2024
@isentropic
Copy link
Author

Yeah I get that it is pretty easy to achieve this via 3rd party, but this if it is core julia then editor tools could take advantage of this extra information. Somehow I feel like unless it is standard julia nobody will conform to standard way of doing this and resort to like 10 different packages and lead to even more confusion. It is just julia allows to much freedom and not opinionated enough for these kind of things. Just my 5cents

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
design Design of APIs or of the language itself feature Indicates new feature / enhancement requests modules
Projects
None yet
Development

No branches or pull requests

2 participants