7 ms·
So the thing is, low-level Windows APIs (such as CreateFile) have supported forward slashes for a long time. And since libc/posix-ish stuff like fopen() is impl
by skrebbel 11y ago
So the thing is, low-level Windows APIs (such as CreateFile) have supported forward slashes for a long time. And since libc/posix-ish stuff like fopen() is implemented with that API on Windows, nearly all programming languages are magically forward/backslash agnostic on Windows. As a programmer, this means that in places where it really matters, you're usually just fine with forward slashes.
Many UIs get confused on forward slashes though (file open dialog, stuff like that), and given that the vast majority of people, worldwide, that understand what files and directories are, believe backslashes are the way to go, I doubt MS is ever going to change this.
But from personal experience - I've programmed cross-platform stuff on Windows for very many years, and I never bothered about backslashes. In all honesty I never understood all the open source stuff that comes with DIRECTORY_SEPARATOR global constants or eslint rules that tell you to use path.join() instead of `dir + "/" + subdir`. The forward slash just works, and it has worked for ages.
The only "problem" is that at times you end up concatenating paths together and end up with stuff like
C:\Temp/mydir/2/..\file.txt
That's a bit quirky in log file and in the debugger. But fopen eats it just fine.
Sure there might be cases where this is a problem, probably the libraries I've seen code around backslashes have good reasons, but really for end-programmers it's no biggie.
Now, MAX_PATH, that's something else. That should die in a fire and it blows my mind that it hasn't been addressed yet.
- capote 11y agoDo you have a source on "vast majority of people ... believe backslashes are the way to go"? And if you do, do you have a source on why? Also, yeah, can anyone clarify what the deal with the max path length is? And why it's possible to create a path above the max length but not to simply delete it from the filesystem?
- SBArbeit 11y agoProbably no source other than: there are 1B+ Windows users (like me) vs. maybe 100M Mac users + a few million Unix-y users.
- jdietrich 11y agoWhat proportion of Windows users actually deal with file paths on a regular basis?
- monochromatic 11y agoOut of people young enough to have missed everything prior to Windows 95, I'd bet that easily 90% have never typed a file path.
- jack9 11y agoAlmost every single working person who deals with URLs or buys things online...or uses facebook has typed a file path styled URL.
- jasonjei 11y agoGreat point. I think cross-platform developers have had enough special macro code for Windows path handling and parsing ;)
- jbergens 11y agoA lot of users open Explorer and looks at the path or copies the path. Nowdays the path is shown with arrows instead of slashes but when you klick on it to edit or copy it will use backslashes. This means a lot of users might have seen them and used them. Even 10% of 1B users is till 100 million users.
- jbergens 11y agoAnother problem is all Windows applications that don't handle forward slashes well. To make minimal inpact on the users all those applications would have to be updated. That will probably never happen.
- mehrdada 11y agoI bet most of those users use internet URLs with slashes more often than filesystem paths.
- al2o3cr 11y agoFrom MSDN on MAX_PATH: https://msdn.microsoft.com/en-us/library/windows/desktop/aa365247(v=vs.85).aspx#maxpath https://msdn.microsoft.com/en-us/library/windows/desktop/aa3... I first encountered this issue when helping new developers get started with NPM on Windows; older NPM versions produced deeply-nested node_modules trees that could easily overflow the limit.
- chris-at 11y ago> the vast majority of people [..] believe backslashes are the way to go Not sure you got that right. I'm certain there are more people that use forward slashed in a browser (every OS+mobile) than people who type backslashes in Windows. My mother has used Windows for years and doesn't even know where the backslash character is. She can type URLs though.
- JoshTriplett 11y agoI've seen URLs printed on paper, posted on signs, and even printed on the side of napkin dispensers, that use backslashes instead of forward slashes. For a long time, the automated message on my university's services number (admissions, etc) started off by spelling out a URL, complete with two mentions of "backslash". It's a very common mistake.
- extra88 11y agoThe phone message error is different though, they mistakenly think '/' is named backslash. I've heard people say this in person multiple times and when I've had a chance I confirmed that when they said "backslash" they were referring to the '/' character.
- seanp2k2 11y agoAs a little kid (~10 years old), I thought it was called a "full colon" (made sense with semicolon, which was my favorite piece of punctuation).
- Stratoscope 11y agoYou just brought back memories of some of the first radio ads I heard that mentioned URLs: "Please visit our world wide web home page at aitch tee tee pee colon, forward slash forward slash, acme period see oh em."
- roywiggins 11y agoI still hear "backslash" invoked in URLs once in a while, and it still bugs me to no end. It's 2016! You are a radio announcer! You should know how to pronounce URLs by now! So frustrating.
- WalterBright 11y agoI keep running into Windows code from Microsoft that still doesn't work with /. It'll probably be there forever. The code I write is regularly ported between OSX, Linux, and Windows, and I routinely make it work with both, as well as being agnostic about line endings. The opposite problem, Linux programs not working well with CRLF, is there as well. I find git to be more or less unusable with CRLF source files, so I run a 'tolf' utility on all checkins. Linux programs ported to Windows tend to run poorly, like being case sensitive on filenames in some places but not in others.
- yuhong 11y agoThe funny thing is that there are not that many Windows APIs that don't have a length parameter for paths (mostly Shell I think).
- devbug 11y agoIn my experience, FindFirstFile and friends don't eat forward slashes, unfortunately.
- ygra 11y agoDIRECTORY_SEPARATOR might just as well exist because of Mac OS which used : as path separator. With the transition to OS X and the Unix filesystem layer above HFS that morphed into /, but in the filesystem it's still : afaik.
- riffraff 11y agoIsn't there an issue with starting subprocesses on windows if using one slash or the other? I seem to remember this as a problem many years ago but I might be wrong
- krylon 11y agoThank you very much for the explanation! I knew I could get away with using forward slashes in Perl and PowerShell, but I had assumed these were hacks in Perl and Powershell respectively, in order to make Unix-people feel slightly more at home. > Now, MAX_PATH, that's something else. That should die in a fire and it blows my mind that it hasn't been addressed yet. In a way, it has. AFAIK, internally Windows can handle paths that are far longer than MAX_PATH, but since so many applications have been written with the assumption that a path can never be longer than MAX_PATH, apparently Microsoft felt if somebody passed a longer path to an API function, that probably indicated some programming error, a buffer overflow or something like that. But apparently, if you write a path like \\?\C:\Some\Really\Long\Path\With\Lots\Of\Nested\Subdirectories\And\A_Ridiculously_Long_Filename_In_It.RandomLongFileExtension then the path can be fairly long. I think there still is a limit of something like 64KB, but that should, as they say, be enough for anyone. ;-) Still, I agree, MAX_PATH and network shares have given me a lot of pain - if you have have file server with a folder like D:\Network_Shares\Accounting that is mapped to, say, the drive E: on some client, the client can create files whose local path on the server will exceed MAX_PATH, causing e.g. backup software to choke. And this happens quite a bit, because our project engineers store project-related files in an elaborate, very deep folder hierarchy; I appreciate they want to organize their files, but sometimes I just want to slap them.