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

Make include accept arbitrary number of string inputs #23428

Closed
wants to merge 1 commit into from

Conversation

baggepinnen
Copy link
Contributor

This method will make include support a call syntax like

include(@__DIR__, "filename.jl")
include(path_variable, "filename.jl")

which is simpler than

include(joinpath(@__DIR__, "filename.jl"))
include(joinpath(path_variable, "filename.jl"))

This is my first PR to julia, I apologize in advance for any breach of protocol.

This method will make `include` support a call syntax like
```julia
include(@__DIR__, "filename.jl")
```
which is simpler than
```julia
include(joinpath(@__DIR__, "filename.jl"))
```
@musm
Copy link
Contributor

musm commented Aug 25, 2017

This seems like it could be confusing; I'd almost think that
include("path_variable", "filename.jl") would include two files, not joinpath the input arguments.

@baggepinnen
Copy link
Contributor Author

The inspiration came from Pkg.dir which has a built-in joinpath, together with the fact that include(joinpath is a very common pattern in Julia code.

The feedback the user would get upon trying to include multiple files would be immediate and rather easy to understand, and if the automatic joinpath makes it more likely that people will use it rather than chaining paths together with the multiplication operator I say it's worth the potential confusion opportunity. It would be documented of course so that all confusion goes away upon reading ?include

@StefanKarpinski
Copy link
Sponsor Member

I'd almost think that include("path_variable", "filename.jl") would include two files

Once upon a time, for a brief while, that's actually what it did: #19909. I have to say, this behavior makes more sense to me as a convenience, but the fact that there's two things it could mean makes me think it might be better to just require using joinpath explicitly.

@StefanKarpinski
Copy link
Sponsor Member

However, I have to say, this is a much more useful behavior for multi-arg include, imo.

@KristofferC
Copy link
Sponsor Member

Is this a bit of a slippery slope? Should all functions that take a path have a vararg joinpath version?

@JeffBezanson
Copy link
Sponsor Member

Welcome, @baggepinnen ! Thanks for the PR.

I have to say I don't really like this though; I'd prefer to keep include and joinpath orthogonal.

@baggepinnen
Copy link
Contributor Author

I would personally like for consistent acceptance of multiple strings with automatic joinpath for all functions that accept a single string path, mostly because I appreciate when it's convenient to do things the right way. I was also considering a special multiplication operator between strings that does "path concatenation" by calling joinpath on its operands. Any thoughts on that idea?

@KristofferC
Copy link
Sponsor Member

JuliaLang/Juleps#26 maybe.

@baggepinnen
Copy link
Contributor Author

That seems like a very promising idea, especially because the simple creation of the Path through the string macro.

@JeffBezanson
Copy link
Sponsor Member

In my experience this is the kind of thing that gives a bit of convenience in the short term, but pain in the long term as new cases are encountered. If a function accepts a path, it should just accept the path as one argument, and how you get the path is an orthogonal concern. That's the only thing guaranteed to work in all cases.

@rfourquet
Copy link
Member

An example where multiple strings can be passed for convenience is warn/error, which are then not orthogonal to string.

@StefanKarpinski
Copy link
Sponsor Member

I suspect that @JeffBezanson doesn't care for that either.

@JeffBezanson
Copy link
Sponsor Member

I just see a lot of potential for confusion in this case. For example, ls and cat traditionally take multiple filename arguments, which conflicts with multiple path arguments implying joinpath. If you saw ls("a", "b") in julia you would have to guess which it means. And obviously, there are many operations on multiple paths like mv where the convention is not applicable. In general, varargs are intrusive since they prevent adding more positional arguments to a function in the future.

With warn and error I don't see as much potential confusion. One reason is that it's not possible to throw two errors at once, and printing two warnings at once (while possible) would be strange. In contrast, includeing multiple files is the common case, and so too for other file operations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants