
On Mon, May 03, 2021 at 11:49:31AM -0700, Christopher Barker wrote:
To be clear, I'm -1 as well -- we just don't need it. but a few thoughts:
On Mon, May 3, 2021 at 6:32 AM Steven D'Aprano <steve@pearwood.info> wrote:
If we have str comprehensions, we'd need at least two prefixes: one for
raw strings, one for regular (cooked) strings.
would we? I don't think so
On further thought, I think you're right. String comprehensions aren't literals; they're not even a hybrid "part literal, part code" like f-strings. So scrub the raw comprehension versions. That just leaves a string version and a bytes version. [...]
Another pillar of your argument is that ''.join is "unintuitive" for newbies. I don't give much weight to that argument.
I think the "".join() idiom is kinda non-intuitive -- heck I've been known, twenty years in, to absentmindedly write:
a_sequence.join(",")
Once in a while.
There is only one truly intuitive interface, and that is the nipple. Everything else is learned. Just because we occasionally screw up and get syntax wrong doesn't make it "unintuitive" in any meaningful sense. We've all messed up code from time to time, especially when we're distracted, or tired and emotional. I've been known to write dicts `{key=value}`, invariably when it is a large dict with dozens of entries. Also `import func from module`, my fingers frequently type string.strip when I meant string.split, and visa versa, and for my most embarrasing mistake I once managed to write a module with no fewer than six classes like this: def MyClass(object): def __init__(self, obj): ... before actually running the code and discovering that it didn't do what I wanted. So I wouldn't read too much into the occasional typo or braino.
And my newbie students defiantly get tripped up by this. But they find comprehensions pretty confusing too :-) so I don't think this would "solve" that minor problem.
Indeed. I found comprehensions confusing too, and that was despite having many years experience with the syntax that inspired it, set builder notation in mathematics. For the longest time I had to literally write out my comprehension using mathematical notation and manually translate it to Python syntax to get anywhere. -- Steve