[Python-ideas] Null coalescing operators

Sven R. Kunze srkunze at mail.de
Wed Sep 23 19:30:12 CEST 2015


On 23.09.2015 00:53, Chris Angelico wrote:
> On Wed, Sep 23, 2015 at 4:22 AM, Sven R. Kunze <srkunze at mail.de> wrote:
>> I can tell from what I've seen that people use None for: all kinds of
>> various interesting semantics depending on the variable, on the supposed
>> type and on the function such as:
>>
>> - +infinity for datetimes but only if it signifies the end of a timespan
> What this means is that your boundaries can be a datetime or None,
> where None means "no boundary at this end".

Yes.

>
>> - current datetime
>> - mixing both
> I don't know of a situation where None means "now"; can you give an example?

range_start = <proper datetime>
range_end = <proper datetime or one of the above>

So, if you need something that ranges from 2015-01-01 to now, you 
basically say the range is expanding. Depending on the function/method, 
it either means until forever, or now.

>
>> - default item in a list like [1, 2, None, 4, 9] (putting in 5 would have
>> done the trick)
> What does this mean? Is this where you're taking an average or
> somesuch, and pretending that the None doesn't exist? That seems
> fairly consistent with SQL.

Imagine you render (as in HTML and the like) 1, 2, 4, 9 and instead of 
the None you render a 3. Now, the rendering engine needs to 
special-check None to put in a pre-defined value. Furthermore, all 
places where you need that list [1, 2, None, 9], you basically need to 
special-check None and act appropriately.

(Of course it was not that simple but you get the idea. The numbers 
stand for fairly complex objects drawn from the database.)

>
> Mostly, this does still represent "no such value".

Point was "no such value" sucks. It can be a blend of every other value 
and semantics depending on the function, type and so forth.

It's too convenient that people would not use it. As the example with 
the list shows us, the 3 could have easily be put into the database as 
it behaves exactly the same as the other objects.


The same goes for the special datetime objects. The lack of thinking and 
appropriate default objects, lead to the usage of None. People tend to 
use None for everything that is special and you end up with something 
really nasty to debug.


Not why people don't find it problematic when I said "we found 6/7 
domain-agnostic semantics for NULL". The "no such value" can be any of 
them OR a blend of them. That, I don't want to see in the code; that's all.

Btw. having the third issue of above, I could add another 
domain-agnostic meaning for None: "too lazy to create a pre-defined 
object but instead using None".


> ChrisA
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/



More information about the Python-ideas mailing list