4 ms·
The built-in file system libraries for many languages are total footguns. Using strings as paths is a great example. I’ve had a few recent bugs around case sens
by mattbierner 8y ago
The built-in file system libraries for many languages are total footguns. Using strings as paths is a great example. I’ve had a few recent bugs around case sensitive vs case insensitive file systems because a lot of code assumes that when pathA != pathB then it must be dealing with two different resources. Not to mention the classic “doesn’t work on windows” problem: newPath = pathA + “/“ + pathB
- lostmsu 8y agoAFAIK, Windows understands / as a directory separator.
- mehrdadn 8y agoOnly in some special cases, not in general.
- dvlsg 8y agoReally? I use forward slashes all the time in windows 10. I don't think I've run into a problem yet.
- mehrdadn 8y agoYes. One huge problem is slashes are also used for command-line switches. That can entirely change the meaning of your commands. For example, compare these two in the command prompt: start /Windows/Notepad.exe start \Windows\Notepad.exe I wouldn't blame this on poor parsing or other silly things though. I actually think it makes sense to use slashes for switches, because they are invalid filename characters, whereas dashes are valid, and hence get ambiguous (hence the need for "--" in *nix). I think it would've made more sense to disallow slashes as directory separators entirely, to avoid this for good.
- gpvos 8y agoThey work everywhere, except on the command line or file dialogue windows.
- beagle3 8y agoOn the contrary. It accepts '/' as a path separator for filenames in every API call. The special case that doesn't is command line parsing (cmd.exe and a few others)
- mehrdadn 8y ago> On the contrary. It accepts '/' as a path separator for filenames in every API call. The special case that doesn't is command line parsing (cmd.exe and a few others) No... assert( PathIsRoot(TEXT("C:\\"))); assert(!PathIsRoot(TEXT("C:/" ))); Also, I believe you meant directory separator, not path separator. Please don't be so tempted to take an antagonistic position and confidently declare other people wrong when you cannot possibly support your position in full... I see this very commonly on HN and I cannot tell you how extremely frustrating it is for those trying to help. It sucks away all the energy and enthusiasm we have for trying to help people get accurate information (meaning we might not even have the energy to bother to respond), and on top of that, you risk disseminating incorrect information. In this case, you simply could not have tried all the wide variety of Windows APIs, so at the very least, maybe say "in my experience" if something is only based on your experience.
- oblio 8y agoMost decent stdlibs have a path.join or an path.separator you can use instead. Just that people don't bother and hardcode...
- SSLy 8y agoIIRC java's stdlib converts `/` to the mentioned separator
- draegtun 8y agoThat's why it's good to have a cross-platform path datatype/literal baked into the language. For eg. in Rebol/Red - http://www.rebol.com/r3/docs/datatypes/file.html http://www.rebol.com/r3/docs/datatypes/file.html