The “does Python have variables?” debate
Steven D'Aprano
steve at pearwood.info
Wed May 7 23:41:44 EDT 2014
On Thu, 08 May 2014 12:09:21 +1000, Chris Angelico wrote:
> On Thu, May 8, 2014 at 11:27 AM, Steven D'Aprano
> <steve+comp.lang.python at pearwood.info> wrote:
>> If I have understood correctly, and I welcome confirmation or
>> correction, one can have any combination of:
>>
>> * dynamic typing and name binding (e.g. Python and Ruby); * static
>> typing and name binding (e.g. Java); * dynamic typing and
>> fixed-location variables (any examples?); * static typing and
>> fixed-location variables (C, Pascal).
>
> Dynamic typing and fixed locations could really only be assembly
> language, I think.
Not so! That's how __slots__ and local variables work in CPython.
Objects are different sizes, so CPython can't allocate a box of a fixed
size unless it knows how big the box needs to be. Fortunately, pointers
are all the same size, so the object lives on the heap and the pointer
goes in the box.
The point being, there could be a language that used fixed locations for
variables, while still being fully dynamically typed. That would allow
the language to use pass-by-name or pass-by-reference semantics instead
of pass-by-value or pass-by-shared-object.
--
Steven
More information about the Python-list
mailing list