6 ms·
Windows again. "Let's use a backslash instead of a slash in paths" has to be up there with "NUL-terminated strings" in terms of tiny bad ideas from long ago tha
by tialaramex 7y ago
Windows again. "Let's use a backslash instead of a slash in paths" has to be up there with "NUL-terminated strings" in terms of tiny bad ideas from long ago that are still haunting us.
Of course it's not as though Google had a choice at the outset, I'm sure some non-trivial number of web sites magically didn't work (and maybe still don't work) if you insist that https://www.example.com\works\fine\on\my\pc https://www.example.com\works\fine\on\my\pc doesn't do what the person writing it expects... I think we can blame some early Internet Explorer build for first having this work (I can't see Netscape allowing it) and then it becomes a choice whether to be a purist or sigh and move on once IE gets popular and real people do it.
- catblast 7y agoThe story goes that Microsoft advocated for a UNIX like path separator for DOS, and it was probably IBM that pushed for the backslash so that they wouldn’t be confused with the option switch character. In any event, blaming Windows for this is a bit silly.
- roywiggins 7y agoOh, I still hear ads giving URLs with inexplicable backslashes in them. "Visit our website at foo.com backslash baz"
- anschwa 7y agoI think few people know the difference, so they say backslash when they mean forward slash.
- dmurray 7y agoThe wrong way round always seemed more logical to me: you write either slash from top to bottom, so for a forward slash your pen moves backwards and vice versa.
- Thorrez 7y agoThe way I remember it is to think of the slash as a little person facing to the right (the direction that text flows). Is the person leaning forward or backward?
- __float 7y agoHow often do you use this device? I feel like I hardly understand the idea, because a / and \ is just as distinct as a b and a p. We don't make mnemonics for those?
- inimino 7y agoNaturally, the occurrence rate of b and p in people's experience, as well as the circumstances in which they are semantically distinct, are also relevant...
- Thorrez 7y agoYeah, honestly not very often. Mostly they're second nature to me. I mainly just think of it when there's a topic of / vs \ like in this thread.
- chrismorgan 7y agoIt seems normal to me to speak of the angle of handwriting as slanting forwards or backwards, corresponding to slash and backslash. Most people’s handwriting is angled either upright or slightly forwards—leaning into the writing; backwards is uncommon.
- JdeBP 7y agoYou now have me wondering whether I have, at any point in my lifetime, written a backslash with a pen. It's an interesting thought that possibly I never have.
- dmurray 7y agoNever had to write down a DOS or Windows path?
- reaperducer 7y agoI still hear ads giving URLs with inexplicable backslashes in them. Can confirm. Just yesterday on NPR.
- icedchai 7y agoThe average person doesn't know the difference between a regular forward slash and a back slash. Why should they?
- cesarb 7y ago> Why should they? The average person does know (or at least should know) the difference between an exclamation mark and a question mark; it's part of literacy. One could argue that knowing the difference between a forward slash and a backslash is part of digital literacy (and that it's a worthy goal for the average person to have digital literacy).
- icedchai 7y agoAn exclamation point and question mark look distinctively different. A forward slash and backward slash may as well be identical.
- AaronFriel 7y agoSeems like the real problem is using a regex to parse a URL instead of using a URL parser!
- dgoldstein0 7y ago... this was within a url parsing library, if I understood correctly? Either way, urls need to be parsed somehow, and using a regex is a reasonable strategy (urls are a regular language) for implementing a url parsing library.
- rasz 7y agonew URL("https://user:pass@xdavidhu.me\\test.corp.google.com:8080/path/to/something?param=value#hash")
- cesarb 7y agoAccording to https://developer.mozilla.org/en-US/docs/Web/API/URL https://developer.mozilla.org/en-US/docs/Web/API/URL that works everywhere except on Internet Explorer, so keeping with the theme of the original comment, we can blame Windows again.
- kazinator 7y agoNUL terminated strings are a great representation. We can take a suffix of a non-empty NUL-terminated string just by incrementing the pointer, which is great for recursion. A pointer to a NUL is itself a valid string. E.g. tail recursive strchr: const char *strchr_rec(const char *str, int ch) { if (*str == 0) return NULL; if (*str == ch) return str; else return strchr_rec(str + 1, ch); } strrchr (rightmost match): const char *strrchr_tail(const char *str, int ch, const char *seen) { if (*str == 0) return seen; if (*str == ch) return strchr_tail(str + 1, str, ch); return strchr_tail(str + 1, seen, ch); } const char *strchr_rec(const char *str, int ch) { return strchr_tail(str, ch, 0); } That kind of thing makes me feel that null terminated strings are the shiznit compared to some clunky header + data or whatever. The only problem is that NUL-terminated strings are so darn easy to program with, everyone who comes into contact with them wants their share of the action, instead of using someone else's well-tested code. As we speak, someone is likely writing yet another loop that builds up a NUL-terminated string directly, and will forget to write the final NUL in some case, or go past the end of the buffer in another. Want to break a string into tokens on delimiters? Just overwrite the delimiters with null bytes and you're done. (Oops, the caller didn't expect their string mutated. Worse, it was a literal ...). If you make programmers maintain a length field followed by data, or some such thing, they will quickly go off scampering for library functions to everything. What we should never do is compare unencapsulated NUL-terminated string manipulation with the manipulation of another representation using a robust, debugged library. Compare open-coded to open-coded, wrapped to wrapped.
- Thorrez 7y agoIs open-coded that much of a benefit over wrapped? With something like std::string_view you can take any substring without new allocations, not just suffixes.
- chrismorgan 7y agoNUL-terminated strings are a poor representation, feature-poor and directly responsible for a great many entirely avoidable bugs. I much prefer the approach used by languages like Rust, where &str and &[T] are (pointer, length) rather than just a pointer. Usage can be identical to your classic NUL-terminated string, depending on the language. (It is in Rust, with CStr.) There is only one potential disadvantage: pointers use twice as much memory; but in practice, this disadvantage is entirely theoretical. But there are several serious advantages: it lets you represent zero values (U+0000 for &str, integer zero for &[u8], &c.), take slices that aren’t suffixes (reducing either code complexity or memory usage, sometimes drastically), calculate the string length in constant time (and that’s regularly a big deal), and avoid a pitfall that has been the cause of many critical security vulnerabilities (buffer overrun). Want to break a string into tokens on delimiters? Easy, regardless of the length of the delimiter (it could be zero, two, seventeen—while with NUL-terminated strings it had to be one), without needing to worry about whether it’s safe to mutate the string.
- aidenn0 7y agoThe backslash as path dates back at least as far as CP/M which didn't have directories and used a forward-slash instead of a minus for command flags. Then when directories were added, a forward-slash was obviously unavailable. [edit] Apparently CP/M took it from VMS, which used period as a path separator.
- catblast 7y agoWonder where you got that information from, since CP/M is older than VMS by like 3 years. Can’t be... wonder where this keeps cropping up. Besides CPM filesystem wasn’t hierarchical.
- aidenn0 7y ago> Wonder where you got that information from, since CP/M is older than VMS by like 3 years. Can’t be... wonder where this keeps cropping up. This stack-exchange post[1] Looks like that's a corruption of the information from a MS blog[2], which does not mention CP/M but DOS 1.0 as taking it from DEC in general, including systems older than VMS. > Besides CPM filesystem wasn’t hierarchical. Which I mentioned in my comment. 1: https://superuser.com/questions/176388/why-does-windows-use-backslashes-for-paths-and-unix-forward-slashes https://superuser.com/questions/176388/why-does-windows-use-... 2: https://web.archive.org/web/20120304135002/http://blogs.msdn.com/b/larryosterman/archive/2005/06/24/432386.aspx https://web.archive.org/web/20120304135002/http://blogs.msdn...
- aidenn0 7y agoDOS couldn't use "/" for paths because it was already using it for command flags (where unix uses "-"). This predates both VMS and CP/M by being used in RT-11 (an older DEC OS).
- reaperducer 7y agoThe backslash as path dates back at least as far as CP/M which didn't have directories and used a forward-slash instead of a minus for command flags. I had a CP/M machine in the 70's, and I remember it quite differently. My memory was that CP/M used normal slashes for directory separation, and the backslash was a Microsoft bodge so it could pretend it didn't have Seattle Computer Products copy CP/M 80 to make DOS. I'm not at home, so I can't verify the slash situation on any of my CP/M emulators. It's also possible that I am not remembering correctly because I was also using Vaxen and PR1MEOS in those years.
- efdee 7y agoDip your ink in Microsoft hate and blame them for something completely unrelated to them: check.