Use cases for del

Ron Adam rrr at ronadam.com
Wed Jul 6 17:18:42 EDT 2005


Reinhold Birkenfeld wrote:

> Ron Adam wrote:
> 
>>Ron Adam wrote:
>>
>>
>>>And accessing an undefined name returned None instead of a NameError?
>>
>>I retract this.  ;-)
>>
>>It's not a good idea.  But assigning to None as a way to unbind a name 
>>may still be an option.
> 
> IMO, it isn't. This would completely preclude the usage of None as a value.
> None is mostly used as a "null value". The most prominent example is default
> function arguments:
> 
> def foo(bar, baz=None):
> 
> With None unbinding the name, what would you suggest should happen? baz being
> undefined in the function scope?

It would be a way to set an argument as being optional without actually 
assigning a value to it.  The conflict would be if there where a global 
with the name baz as well.  Probably it would be better to use a valid 
null value for what ever baz if for.  If it's a string then "", if its a 
number then 0, if it's a list then [], etc...

If it's an object... I suppose that would be None...  Oh well. ;-)

> Or, what should happen for
> 
> somedict[1] = None

Remove the key of course.

       var = somedict[1]  Would then give an error.

and

       (somedict[1] == None)  Would evaluate to True.


> ? Also, the concept of _assigning_ something to a name to actually _unassign_
> the name is completely wrong.

That's not anymore wrong than ([] == [None]) --> False.

Having a None value remove a name binding could make the above condition 
True.

> Of course, this is a possible way to unassign names if (and only if)
> (1) there is a real "undefined" value (not None)
> (2) unbound names return the undefined value
> 
> Look at Perl. Do we want to be like that? ;)
> 
> Reinhold

The problem I had with perl is that number of symbols and ways of 
combining them can be quite confusing when you don't use it often.  So 
it's either a language you use all the time... or avoid.

Anyway, there seems to be enough subtle side effects both small and 
large to discount the idea.  While implementing it may be possible, it 
would require a number of other changes as well as a different way of 
thinking about it, so I expect it would be disliked quite a bit.

Cheers,
Ron



More information about the Python-list mailing list