On Tue, Jul 24, 2018 at 08:07:36AM -0400, Richard Damon wrote:
The fact that you changed NullCoalesce into Foo to show lack of explicitness seems a straw-man.
I understood Rhodri as making the point that if you don't know what NullCoalesce means or does, it might as well be called Foo. There's no hint in the syntax that something magical is happening: MyClass(obj).spam.eggs # ordinary attribute lookup YourClass(obj).spam.eggs # still ordinary attribute lookup Mxyzptlk(obj).spam.eggs # looks like ordinary attribute lookup NullCoalesce(obj).spam.eggs # IT'S A TRAP!
Words are FULL of meaning, while symbols are less so.
It isn't a competition to squeeze as much meaning as possible into a single word or symbol. Precision is more important than fullness. A case in point: the word "add" has six meanings listed by WordNet, and the Mobi Thesaurus gives 102 synonyms for it. A function or method called "add" could do anything: - add users to a database; - add pages to a chapter; - add elements to a set; - add items to a queue; etc. In contrast, the + symbol in Python has two standard meanings: - numeric addition; - sequence concatenation; and while it is true that with operator overloading a class could make the + operator do anything, that is usually taken as an argument to avoid operator overloading, or at least use it cautiously. Surely you don't think that the + operator is a mistake because the word "add" is more full of meaning than the symbol? If not, what point were you trying to make?
The biggest issue I see with the use of ? here is that ? does have some meaning, it says we are going to be (or have) asked a question, it doesn’t tell us what the question is.
Sometimes you just have to learn the meanings of words or symbols. What does NullCoalesce mean? Until this PEP was proposed, I had no idea this was even a thing, and in truth I actually had to look up "coalesce" in a dictionary to be sure I understood it correctly, because the context doesn't seem quite right. (It still doesn't -- it might be the standard comp sci term for this feature, but I don't think it quite matches the ordinary usage of the word.) Ask a dozen programming beginners what "NullCoalesce" does, and I expect every one of them will say "No idea". Strangely enough, nobody complains about having to learn what "import" does, or slicing syntax x[:], or string backslash escapes "\n", or "property". Because we're used to them, we just accept that you have to learn the meaning of things the first time you see them. We aren't born knowing what "class" does, or the difference between x[a] and x(a). Every single one of us, without exception, had to learn what . means at some point or another. And yet, its wailing and gnashing of teeth and panic in the streets over the idea that people might have to learn what ?. means in the same way they learned what **kwargs or mylist[1:] or obj.attr means. "It's a question, but what is the question? How will I ever find out? If only there was a website where I might look up Python operators and learn what they do!!!"
?. has some indication that we are doing an attribute access that is in some way conditional, but a?.b could mean that we are conditional on a not being null, or it could be asking to suppress any and all error in getting b, even if a is an int and thus doesn’t have a b. The words carry a lot more meaning.
Yeah, because words are always obvious. import ast # Who can remember all these damned TLAs? import bdm # Births Deaths Marriages? import csv # Court Services Victoria? import mailcap # what the postman wears on his head? import pickle # something to do with condiments? import turtle # somebody is taking the micky import curses # good thing I'm not superstitious "But Steve, you don't understand. Having to learn the meaning of words you haven't learned before is right and proper and unavoidable. But all new punctuation symbols must be intuitively obvious to newborn babies, or else they are the Devil's Mark, or Perl, not sure which is worse." (Its called sarcasm, not "strawman". Just sayin'.) -- Steve