-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
define /(string,string) = joinpath for strings? #9488
Comments
Beyond overloading for Strings, I would also (re)consider a specific type. Agreed that / for all strings would be weird. If path where a specific type you could have / on string return a path. I found an old discussion about specific type for path in 2012 (sorry phone so no link), Jeff was against. One of the advantage I suppose would be that you can insure that a path would alway be consistent (no double / in the middle) and/or use \ for separator in windows, directory ends with trailing /... Etc I think it would also simplify the vocabulary so that you could call split and join or even abs without post fixing everything with "path" I believe a second similar subtype for URI would be interesting (differ from path by the fact that there would be no /->\ on windows. Python 3.4 iirc introduce a notion of path class exactly for these issues that are painful. And in IPython the not having path/uri type is a huge pain, especially since we map uri to path for the webserver. Envoyé de mon iPhone
|
One more thing for a path type is that you could define a subtype "ResolvedPath" when you can be insured that /something/../ or ~/path are alway expended and or collapsed. One of the recurrent PR we get on IPython is that we did not called expand user or abspath in some string somewhere and that it breaks on some system with some particular configuration of symlink/non-root install. IIUC (with my little knowledge of Julia) promotion/conversion would be of great help. Envoyé de mon iPhone
|
Jeff wasn't a fan: #1548 |
Ah, closing in favor of #1548. |
An interesting suggestion made by @Carreau in JuliaLang/IJulia.jl#210 was to define
/
for strings asjoinpath
.This would make file-handling code a lot cleaner looking, e.g. compare
joinpath("METADATA", pkg, "versions")
to"METADATA"/pkg/"versions"
.joinpath
is probably one of the most common uses of string concatenation (I count almost 60 calls in Base).Con: we've usually avoided in Julia this kind of "cute" overloading that completely changes the meaning of an operator, and this would make
/
for strings completely unrelated to an inverse*
(concatenation) for strings. Pro: working with files is one of the most central tasks in any programming language, and/
is way easier and more readable thanjoinpath
. It seems unlikely that we will provide an approximate division operation for strings, and one can always use÷
for exact "division" (suffix stripping).Just wanted to throw the idea out there.
The text was updated successfully, but these errors were encountered: