[Python-ideas] Null coalescing operator

Steven D'Aprano steve at pearwood.info
Sat Oct 29 02:30:38 EDT 2016


On Sat, Oct 29, 2016 at 11:02:36AM +0900, Stephen J. Turnbull wrote:

> Unfortunately here the most plausible syntax is one
> that Guido has said he definitely doesn't like: using '?'.  The
> alternatives are pretty horrible (a Haskell-like 'maybe' keyword, or
> the OPEN SQUARE character used by some logicians in modal logic -- the
> problem with the latter is that for many people it may not display at
> all with their font configurations, or it may turn into mojibake in
> email.

I think you mean WHITE SQUARE? At least, I can not see any "OPEN SQUARE" 
code point in Unicode, and the character you use below □ is called WHITE 
SQUARE.


> OTOH, that case was an astral character -- after Guido announced his
> opposition to '?', the poster used PILE OF POO as the operator.  OPEN
> SQUARE is in the basic multilingual plane, so probably is OK if the
> recipient can handle Unicode.  '?' vs. '□': maybe that helps narrow
> the choice set?

I cannot wait for the day that we can use non-ASCII operators. But I 
don't think that day has come: it is still too hard for many people 
(including me) to generate non-ASCII characters at the keyboard, and 
font support for some of the more useful ones are still inconsistent or 
lacking.

For example, we don't have a good literal for empty sets. How about ∅? 
Sadly, in my mail client and in the Python REPR, it displays as a 
"missing glyph" open rectangle. And how would you type it?

Ironically, WHITE SQUARE does display, but it took me a while to realise 
because at first I thought it too was the missing glyph character. And I 
still have no idea how to type it.

Java, I believe, allows you to enter escape sequences in source code, 
not just in strings. So we could hypothetically allow one of:

    myobject\N{WHITE SQUARE}attribute
    myobject\u25a1attribute


as a pure-ASCII way of getting

    myobject□attribute


but really, who is going to do that? It is bad enough when strings 
contain escape sequences, but source code?

So even though I *want* to use non-ASCI operators, I have to admit that 
I *can't* realistically use non-ASCII operators. Not yet.


Wishing-that-somebody-can-prove-me-wrong-ly y'rs,



-- 
Steve


More information about the Python-ideas mailing list