[Python-ideas] Suggestion: Extend integers to include iNaN

Steve Barnes gadgetsteve at live.co.uk
Sat Sep 29 03:33:38 EDT 2018



On 29/09/2018 08:18, Michael Selik wrote:
> On Fri, Sep 28, 2018 at 11:32 PM Steve Barnes <gadgetsteve at live.co.uk> wrote:
>> One of the strengths of the IEEE float, (to set against its many
>> weaknesses), is the presence of the magic value NaN. Not a Number, or
>> NaA, is especially useful in that it is a valid value in any
>> mathematical operation, (always returning NaN), or comparison, (always
>> returning False). In functional programming this is especially useful as
>> it allows the chain to complete after an error while retaining the fact
>> that an error occurred, (as we got NaN).
> 
> The inventor of "null reference" called it a billion-dollar mistake
> [0]. I appreciate the Zen of Python's encouragement that "errors
> should never pass silently." Rather than returning iNaN, I'd prefer my
> program raise an exception. Besides, you can use a None if you'd like.
> 
> [0] https://en.wikipedia.org/wiki/Tony_Hoare
> 
In the embedded world, (where I have spent most of my career), it is 
often the case that you need your code to always finish and if an error 
occurred you throw it away at the end or display the fact that you could 
not get a sensible answer - I am reasonably sure that the same is true 
of functional programming.

I am not asking that the original error pass silently, (unless 
explicitly silenced), but rather having the option, when silencing (and 
hopefully logging hat an error occurred) to have a value that will pass 
through the rest of the processing chain without raising additional 
exceptions which None would be likely to do unless expressly tested for 
everywhere. This simplifies the overall code structure while retaining 
the fact that an error occurred, (and the log needs to be checked), 
without the dangerous practice of returning a valid value and setting an 
error flag, (checking of which is often neglected).
-- 
Steve (Gadget) Barnes
Any opinions in this message are my personal opinions and do not reflect 
those of my employer.

---
This email has been checked for viruses by AVG.
https://www.avg.com



More information about the Python-ideas mailing list