|
|
Subscribe / Log in / New account

Formalizing f-strings

Formalizing f-strings

Posted Jan 11, 2023 8:24 UTC (Wed) by SLi (subscriber, #53131)
Parent article: Formalizing f-strings

I started to wonder why nested quotes seem harder to parse than nested parentheses. Is it simply because we're used to parentheses?

It's not. It's because we have separate opening and closing parentheses.

I'm not sure how seriously I'm proposing this, but separate opening and closing quotes exist. Perhaps Python should support them.


to post comments

Formalizing f-strings

Posted Jan 11, 2023 9:11 UTC (Wed) by dtlin (subscriber, #36537) [Link] (3 responses)

In Perl, q(...)/q<...>/q[...]/q{...} can be used instead of '...', and qq(...)/qq<...>/qq[...]/qq{...} can be used instead of "...".
In Ruby, %q(...)/%q<...>/%q[...]/%q{...} can be used instead of '...', and %Q(...)/%Q<...>/%Q[...]/%Q{...} can be used instead of "...".
(They both allow for other delimiters as well, but then open and close are the same character.)

I don't think this approach would be accepted in Python, though.

Formalizing f-strings

Posted Jan 11, 2023 18:56 UTC (Wed) by mbunkus (subscriber, #87248) [Link]

In Perl you can also use any other single-character delimiter, not just the various pairs of parenthesis, both for single & double quotes. E.g.

my $s = qq|This is "nice", I guess, and $this_var will be interpolated!|;

Even C++ has raw strings with custom delimiters now: R"delimiter( raw_characters )delimiter", e.g.

auto s = R"!(This is "nice", I guess!)!";

Formalizing f-strings

Posted Jan 12, 2023 2:39 UTC (Thu) by NYKevin (subscriber, #129325) [Link] (1 responses)

Python mostly doesn't need it, because of r-prefixed triple quoted strings. Unless you *happen* to need to write three consecutive apostrophes *and* three consecutive double quotation marks in the *same* string literal, it's Good Enough, and so it naturally displaces any alternative based on what other languages may happen to be doing.

(On top of that, Python has, perhaps surprisingly, inherited the "consecutive " "string " "literal " "concatenation" behavior of C, so you can just use two separate string literals if absolutely necessary, and the compiler will concatenate them for you, as if you had written a single string literal. Of course, Python also has peephole optimization and basic constant folding, so this is arguably unnecessary - you could just use plus to concatenate.)

Formalizing f-strings

Posted Jan 12, 2023 6:37 UTC (Thu) by SLi (subscriber, #53131) [Link]

I'm probably as used to straight ASCII quotation marks (and irritated by other styles) as any, but I feel this is could be a case where we don't understand what we're missing out on. Would you also say we wouldn't need separate left and right parentheses if we could just triple them, like |||?

When I think about it, it just seems kind of nonsensical to use the same thing to start and end something.

Formalizing f-strings

Posted Jan 11, 2023 19:00 UTC (Wed) by pavon (guest, #142617) [Link] (4 responses)

I think that the left and right quote marks aren't different enough to stand out in the way that left and right parentheses do. It is more on the level of a subtle typesetting improvement, than jumping out at you, at least for the english convention. Which brings up the complications of there being multiple variations on the opening quote character (is it high or low, and does the character face upwards or downwards. Worse some languages like Finnish and Swedish use what English would consider the closing quote mark for both opening and closing. So do you allow all these variations, or just some? I don't know that it would end up being an improvement, other than letting you copy-paste between a word-processor without breaking the code :)

Formalizing f-strings

Posted Jan 11, 2023 20:18 UTC (Wed) by dtlin (subscriber, #36537) [Link] (3 responses)

Whose left/right quote marks? The French-style guillemets «...» are more visually distinct than either the English-style “...” and less confusable with other punctuation symbols than the German-style „...“.

If those don't stand out enough, there are many CJK brackets to choose from: 《...》, 「...」, 『...』, 【...】, and more.

Of course, I'm not being entirely serious here, but for comparison, Raku allows for all of those quotes, and then some.

Formalizing f-strings

Posted Jan 11, 2023 21:17 UTC (Wed) by mathstuf (subscriber, #69389) [Link]

Looking at this page, Sweden and Finland use "fancy quotes", but only the "end" one for both delimiters. `»quoted»` is also recognized apparently.

https://jakubmarian.com/map-of-quotation-marks-in-europea...

Raku

Posted Jan 12, 2023 2:33 UTC (Thu) by stephen.pollei (subscriber, #125364) [Link]

There is actually a lot that I love about raku... wish it was a bit more popular and had better support.

Formalizing f-strings

Posted Jan 12, 2023 11:00 UTC (Thu) by shiar (subscriber, #67206) [Link]

So does (or will) Perl: use experimental 'extra_paired_delimiters' in v5.36.


Copyright © 2025, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds