
On Mon, Jan 17, 2022 at 11:18 AM Steven D'Aprano <steve@pearwood.info> wrote:
On Sun, Jan 16, 2022 at 11:41:52PM +1100, Chris Angelico wrote:
On Sun, Jan 16, 2022 at 11:18 PM Steven D'Aprano <steve@pearwood.info> wrote:
Not to mention:
r(1, 2, 3) # look up r, call it with parameters r[1, 2, 3] # look up r, subscript it r"1, 2, 3" # a string literal
Strings behave differently in many many ways. Are there any non-string types that differ?
There are plenty of non-string types which differ :-)
*sigh* I know you love to argue for the sake of arguing, but seriously, can't you read back to your own previous message and get your own context? With punctuation like parentheses, square brackets, angle brackets, etc, does not ever, to my knowledge, have prefixes. ONLY strings behave differently. Are there any non-string types which have special behaviour based on a prefix, like you're suggesting for sets?
You were concerned that adding a prefix to a delimiter in the form of f{...} would be a bug magnet, but we have had prefixes on delimiters for 30 years in the form of r"..." etc, and it hasn't been a problem.
Yes. ONLY on strings. That's exactly what I said. Strings are different. For starters, we already have multiple different data types that can come from quoted literals, plus a non-literal form that people treat like a literal (f-strings). Is there any non-string type that doesn't follow that pattern?
I mean, sure, the occasional beginner might get confused and write
len{mystring}
and if by some fluke they call f() rather than len() they will get a silent failure instead of a SyntaxError, but is this really a serious problem that is common enough to get labelled "a bug magnet"?
len{mystring} looks a lot like len(mystring), but len"mystring" looks very very different. Or do you treat all punctuation exactly the same way?
I've been coding in Python for two decades and I still occassionally mess up round and square brackets, especially late at night, and I won't tell you how often I write my dict displays with equal signs {key=value}, or misspell str.center.
And I still cringe about the time a few years back where my brain forgot that Python spells it "None" rather than "nil" like in Pascal, and I spent about an hour writing a ton of "if obj is nil"... tests.
Typos and brain farts happen.
You mess up round and square brackets, yes. You might mess up double and single quotes, too, in languages that care. But you aren't going to mess up brackets and quotes.
Triple quoted strings say hello :-)
See above, strings are different, and people treat them differently.
Do they? How are they different? You have a start delimiter and an end delimiter.
The only difference I see is that with strings the delimiter is the same, instead of a distinct open and close delimiter. But that difference is surely not a reason to reject the use of a prefix.
"We can't use a prefix because the closing delimiter is different from the opening delimiter" does not follow.
People treat them differently. That's why f-strings are a thing: we treat strings as strings even when they're expressions. Strings ARE special. I asked you if there are any non-strings that are similarly special. You have not found any examples. ChrisA