3 ms·
ruby does this too, and I think it's a great design. I know it's too late for python to go that route, but I wish they had way back when, rather than having sin
by zem 7y ago
ruby does this too, and I think it's a great design. I know it's too late for python to go that route, but I wish they had way back when, rather than having single and double quotes be the same thing.
- BerislavLopac 7y agoPython's mechanism for this is using a single-character prefix, which would still be needed even if it followed the Ruby/PHP syntax -- simply because Python has at least four different types of string literals: * f"f-strings", which do both substitution and escaping * regular "strings", which do escaping but no substitution * r"r-strings" (for "raw"), which do neither * b"b-strings", which are actually not strings but sequences of bytes
- pansa2 7y agoThere are also `fr`-prefixed strings, which do substitution but no escaping, and `br`-prefixed raw byte sequences.
- BerislavLopac 7y agoExcellent point, thank you! There are also the u"u-strings" which were reintroduced to reduce the workload when converting the Python 2 programs; unfortunately they forgot to do the same for the relatively common (at least when defining regular expressions) ru"ru-strings" and ur"ur-strings"...
- pansa2 7y agoDoes Ruby support strings that do escaping but not variable interpolation? It's interesting if not, because that's the behavior of Python's "normal" strings.
- wruza 7y agoSo does perl, sh, etc, and god knows how long it goes back in time, and even when a language doesn’t, it always strikes as a frivolous move to make two characters to mean the same. Either do 's or "s but both... it’s just a fuel for style(9) wars. The only cases when it’s reasonable is sqlite-like ones, when your goal is to support as many legacy habits as possible.