pep 336: Make None Callable

Chris Cioffi evenprimes at gmail.com
Thu Nov 4 16:39:31 CET 2004


At first I really liked this idea, however as I thought about it I
really came to dislike it.

None isn't Null.  I write a lot of dispatch style code and I use the
fact that None isn't callable to speed up debugging.  I'll do
something like this:

if __debug__:
    noop = None
else:
    noop = DoNothing
methods.get(value, noop)()

This lets me catch errors quickly while debugging, and lets my
DoNothing function (which may just log the fact that a error occured)
keep the program running as long as possible.  I suspect that this
idiom is fairly common.

While I would support the addition of a builtin Null object (I stole
the one from then cookbook for my use), I don't like the idea of
extending None.

While right now it's more of a viseral gut feeling, I really like the
idea that None is the anti-object.  It is itself and nothing more. 
Even when we type it: None.  it's the only builtin that is
capitalized.  Not just a none, but the None.  The definate article. 
The alpha and omega, unchanging and unwilling to act.

My vote is -1.

Chris

On Wed, 03 Nov 2004 20:59:43 -0700, The Eternal Squire
<eternalsquire at comcast.net> wrote:
> PEP: 336
> Title: Make None Callable
> Version: $Revision: 1.1 $
> Last-Modified: $Date: 2004/11/03 16:58:30 $
> Author: Andrew McClelland
> Status: Draft
> Type: Standards Track
> Content-Type: text/plain
> Created: 28-Oct-2004
> Post-History:
> 
> Abstract
> 
>     None should be a callable object that when called with any
>     arguments has no side effect and returns None.
> 
> Motivation
> 
>     To allow a programming style for selectable actions that is more
>     in accordance with the minimalistic functional programming goals
>     of the Python language.
> 
> Rationale
> 
>     Allow the use of None in method tables as a universal no effect
>     rather than either (1) checking a method table entry against None
>     before calling, or (2) writing a local no effect method with
>     arguments similar to other functions in the table.
> 
>     The semantics would be effectively,
> 
>         class None:
> 
>             def __call__(self, *args):
>                 pass
> 
> How To Use
> 
>     Before, checking function table entry against None:
> 
>         class Select:
> 
>             def a(self, input):
>                 print 'a'
> 
>             def b(self, input):
>                 print 'b'
> 
>             def c(self, input);
>                 print 'c'
> 
>             def __call__(self, input):
>                 function = { 1 : self.a,
>                          2 : self.b,
>                          3 : self.c
>                        }.get(input, None)
>                 if function:  return function(input)
> 
>     Before, using a local no effect method:
> 
>         class Select:
> 
>             def a(self, input):
>                 print 'a'
> 
>             def b(self, input):
>                 print 'b'
> 
>             def c(self, input);
>                 print 'c'
> 
>             def nop(self, input):
>                 pass
> 
>             def __call__(self, input):
>                 return { 1 : self.a,
>                      2 : self.b,
>                      3 : self.c
>                        }.get(input, self.nop)(input)
> 
>     After:
> 
>         class Select:
> 
>             def a(self, input):
>                 print 'a'
> 
>             def b(self, input):
>                 print 'b'
> 
>             def c(self, input);
>                 print 'c'
> 
>             def __call__(self, input):
>                 return { 1 : self.a,
>                      2 : self.b,
>                      3 : self.c
>                        }.get(input, None)(input)
> 
> References
> 
>     [1] Python Reference Manual, Section 3.2,
>         http://docs.python.org/ref/ref.html
> 
> Copyright
> 
>     This document has been placed in the public domain.
> 
> Local Variables:
> mode: indented-text
> indent-tabs-mode: nil
> sentence-end-double-space: t
> fill-column: 70
> End:
> --
> http://mail.python.org/mailman/listinfo/python-list
> 


-- 
<a href="http://spreadfirefox.com/community/?q=affiliates&id=0&t=1">Get
Firefox!</a>



More information about the Python-list mailing list