Official definition of call-by-value (Re: Finding the instance reference...)

Steve Holden steve at holdenweb.com
Tue Nov 18 12:14:44 EST 2008


Steven D'Aprano wrote:
> On Mon, 17 Nov 2008 18:35:04 -0800, Craig Allen wrote:
> 
>>>>> * Do all objects have values? (Ignore the Python
>>>>>  docs if necessary.)
>>>> If one allows null values, I am current thinking yes.
>>> I don't see a difference between a "null value" and not having a value.
>>>
>>>
>> I think the difference is concrete... an uninitialized variable in C has
>> no value, I'd say, because the value it will have is indeterminate, it
>> will be whatever happens to be sitting at that location in memory,
>> inconsistent.  If that variable is initialized to some value
>> representing "none", like NULL, then it has a consistent value of
>> "none".  There is no way to have an uninitialized variable in python, so
>> they are always consistently set, so they always have values.
>>
>> ?
> 
> Well said.
> 
> I'd even go so far as to say that an uninitialized variable in C has a 
> random value, unless the compiler prevents you from accessing it. If the 
> compiler lets you (accidentally, I assume!) do something with an 
> uninitialized variable, then you're accessing whatever random value it 
> happens to get.
> 
> 
I think the correct terminology would be "the value of the variable is
undefined", meaning that each implementation is free to use whatever
behavior it likes.

Most C implementations will (I believe) end up with random data in those
variables rather than taking the time to initialize them to some
recognizable value (although some implementations have done that), and
this can be a fruitful source of non-repeatable segmentation faults and
inexplicable behaviors.

The nice thing about Python's ability to create variables on assignment
is that you will either get an UnboundLocalError or a NameError or an
AttributeError exception if you try to access a name that hasn't been
defined. This nicely parallels KeyError and IndexError behavior with
container objects.

regards
 Steve
-- 
Steve Holden        +1 571 484 6266   +1 800 494 3119
Holden Web LLC              http://www.holdenweb.com/




More information about the Python-list mailing list