osdir.com


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

References, and avoiding use of “variable” (was: Can global variable be passed into Python function?)


"Mark H. Harris" <harrismh777 at gmail.com> writes:

> So, yeah, thinking about variables is just not going away.

Right. I would like, ideally, for the Python documentation to avoid
mentioning that term entirely; and I would hope for that to promote a
better understanding of Python's data model.

The wider programming community, though, will no doubt continue to use
that term to refer to various (incompatible) data models, and I
certainly don't expect the Python community to pretend it doesn't exist.

I encourage getting rid of it from Python documentation, but not getting
rid of it from discussion in the community.

> I finally decided (in my own head) that I would completely give up on
> the 'variable' concept (intellectually)  and help folks try to
> understand references and reference counting.

Reference counting isn't a concept one needs to present to newcomers,
IMO. It is sufficient to explain that the Python runtime is free to
discard an object when nothing refers to it any more.

There's no need to explain to a newcomer the garbage-collection
implementation details, precisely *because* it's an implementation
detail. Some Python implementations use reference counting, some don't,
and each implementation is free to do what it likes so long as the data
model guarantees are preserved. The user normally shouldn't care,
because they shouldn't have to depend on any specific garbage-collection
behaviour.

So: it's good to present the concept of ?references?, and use ?name
binding? instead of ?variable?; but there's no need to present
?reference counting?, which is a Python-implementation-detail technical
concept that IMO doesn't need to be in the newcomer's head.

-- 
 \      ?The trouble with the rat race is that even if you win, you're |
  `\                       still a rat.? ?Jane Wagner, via Lily Tomlin |
_o__)                                                                  |
Ben Finney