5 ms·
> Why not a regular slash because how do you parse let x = a/foo(); is that a::foo() or a / foo()? If you use \ it's unambiguous, a\foo() corresponds to
by iopq 10y ago
> Why not a regular slash
because how do you parse
let x = a/foo();
is that a::foo() or a / foo()?
If you use \ it's unambiguous, a\foo() corresponds to a::foo() while a/foo() is division
- kbenson 10y agoExactly. Forward slash has problems. Backslash has problems. Associating the concept with file paths too much has problems (depending on the language and the module implementation). So, why again is :: such a bad choice, given all this?
- iopq 10y agoBackslash does not have problems. It's a single character and looks like windows paths. :: is two characters and is only familiar for C++ programmers (and means something else in PHP)
- kbenson 10y agoBackslash is the single most problematic visible character to represent in lower ASCII. It's the go-to solution for representing the non-visible characters when you need them in a string representation in most languages I can think of. Many errors have been found in string handling routines because of incorrect escape handling. I wouldn't willingly use it as a special character in any language I had input in designing. Even for windows paths, backslash has caused a lot of problems in various tools[1][2][3]. Just google "backslash path error" for many pages of problems. Even early DOS developers weren't happy with the need for backslash, and made regular slashes work in paths. That doesn't work everywhere in Windows, but it works in a lot of places. Following Microsoft's mistake because of an accident of history (they has already used forward slash for command flags before implementing path hierarchies so needed a different character) and dealing with the same problems they have is not a point in backslash's favor. > :: is two characters and is only familiar for C++ programmers It's familiar for whoever learns it for the language they are learning. That it does not necessarily have an association with concepts from other languages or systems that don't apply cleanly (such as the namespace corresponding to the path, which may not be true) is a positive. 1: https://pythonconquerstheuniverse.wordpress.com/2008/06/04/gotcha-%E2%80%94-backslashes-in-windows-filenames/ https://pythonconquerstheuniverse.wordpress.com/2008/06/04/g... 2: https://github.com/rstudio/shiny/issues/1009 https://github.com/rstudio/shiny/issues/1009 3: http://www-01.ibm.com/support/docview.wss?uid=swg21635233 http://www-01.ibm.com/support/docview.wss?uid=swg21635233
- iopq 10y agoThat's \ inside of paths and strings. Nothing to do with \ used in a language. Nobody has an issue with \ used in PHP. The only problem is maybe pasting code on a blog or something, not really a problem when programming in PHP.
- kbenson 10y agoEverything eventually gets represented by a string somewhere. Paths aren't inherently strings, but that's how they are often represented in code. You won't be defining your namespaces as a string in normal usage, but some things do need oto represent source, so why choose a character that makes their jobs harder. There are parallels. It's a downside of using backslash. It's not guaranteed to cause a problem, but the potential is there and waiting for anyone that needs to deal with representing it in language.
- iopq 10y agoBy string, I of course speak of string literals. The only place where this would be an issue is writing Rust compiler error messages. I don't consider that a strong argument for why the path analogy should be broken. Because the path analogy is broken, modules in Rust have strange rules. For example, use foo::bar; doesn't actually use a relative "path" from the current module you need to use use self::foo::bar; I think this is a confusing default, and it would have never ended up this way if Rust used Windows-path-looking namespace syntax if you're writing a parser and manipulating actual arrays of bytes, you don't have an issue with backslash, it's just another character to you