4 ms·
I exploited that when writing a Java app that was targeting Linux and Windows about a decade ago. Got some backlash from colleagues about not using File.pathSep
by iforgotpassword 3y ago
I exploited that when writing a Java app that was targeting Linux and Windows about a decade ago. Got some backlash from colleagues about not using File.pathSeparator or whatever it was called, because the purists argued that we might one day support some platform where the forward slash doesn't work. When they failed to give an example it was decided to keep it that way. Makes for much more readable path names in code.
More than ten years later and I still think it was the right choice.
- freedomben 3y agoHeh, I was one of those purists! I do still prefer using `File.pathSeparator` but I fully concede that it is a useless and unneeded abstraction so my preference is likely purely religious. All in all, I think the Java world suffers majorly from that extreme abstractions. Never in my life have I worked in a language/ecosystem with more (and often unnecessary) abstractions than in Java. Pretty good language overall, but the culture could really benefit from some good old fashioned pragmatism
- vips7L 3y agoThe Path api will choose the right separator for you. Thinking about it really is a non-concern nowadays.
- LoganDark 3y agoYeah, usually I don't bother with manually inserting separators and instead use Path.join or whatever else. It'll do the right thing on basically all platforms.
- 9dev 3y agoThey still have a point, though. There are virtually no platforms that don’t support forward slashes, yet there are abstractions in place to avoid simply using slashes. This may be irrelevant, but it’s still a useless layer of complexity.
- LoganDark 3y agoI generally don't like to treat paths as strings just like I don't like to treat pointers as memory addresses. But hey, you don't always have to care about that stuff to make a functioning piece of software. You know, pick your battles, or however the saying goes. (Not intended to be sarcastic, just in case it comes off that way. I only add the "useless layer of complexity" because it makes the intention more explicit for me.)
- vips7L 3y agoIt is not a useless layer of complexity. Encapsulating paths in an object isn’t purely about slashes.
- JdeBP 3y agoFor what it's worth, .NET Core has the same capabilities of abstracting away pathname separators, if one wants it. Personally, I don't regard such things as useless and unneeded; because I see the value in not writing programs that break what has been a well-known piece of computer lore for 4 decades: namely that one can be Unix-like to a degree on non-Unix platforms such as MS-DOS, DOS+Windows, OS/2, and Windows NT.
- Qwertious 3y agoAccording to [1], Mac supports using slashes as part of folder names (they use colons instead). So there might be some circumstances where that decision comes back to bite you, if you ever port to Mac. [1]https://discussions.apple.com/thread/677339?sortBy=best https://discussions.apple.com/thread/677339?sortBy=best
- iforgotpassword 3y agoHeh, memory is foggy but I think one colleague occasionally ran it on his Mac without issues. I guess your linked thread is good advice, just dont't do it – like using spaces in filenames sooner or later makes a random shell script go haywire.
- elmimmo 3y agoThey used colon instead, back in pre OS X days. That’s >20 years ago. Admittedly some obscure cases carried that over and remain but you’ll rarely come across them today.
- kragen 3y agoyes, if by 'mac' you mean macos 9 or earlier, which was a consideration when java was designed but generally not anymore
- javawizard 3y agoOh it's even weirder than that: whether or not paths are separated by colons or slashes is specific to the app you're using, even in modern macOS versions. To see this in action, open a terminal, type: touch test:file.txt Then open Finder and browse to whatever folder you were in and you'll see a file called test/file.txt. I'm not sure which is the native representation, but I do know that every API I've used to interact with the filesystem on macOS has used slashes as the path separator, so GP should be fine. But it's definitely a fun party trick to pull out around unsuspecting Mac users.
- RedlineTriad 3y agoAccording to this post[0] (though I never tested it), sometimes, when using long paths, Windows will disable the forward/backwards slash normalization. [0] https://news.ycombinator.com/item?id=37632232 https://news.ycombinator.com/item?id=37632232