[Python-ideas] binding vs rebinding

Terry Reedy tjreedy at udel.edu
Thu Feb 5 22:54:12 CET 2009


spir wrote:
> Hello,
> 
> I wonder why there is no difference in syntax between binding and rebinding. Obviously, the semantics is not at all the same, for humans as well as for the interpreter:
> * Binding: create a name, bind a value to it.
> * Rebinding: change the value bound to the name.

Python has several name-binding statements other that assignment.
1. augmented assignments
2. for loops (mentioned by Mark already)
3. import statements (several variations)
4. class statements
5. def statements
Any proposal to adjust one should uniformly adjust all.

All binding statements currently have the same meaning:
   if name is currently bound: unbind it
   bind it to the indicated object
If not currently bound, the unbind step is obviously skipped.
Simple to understand.

Requiring the programmer to indicate whether the unbind step *must* be 
done or not makes more work and pain for the programmer. It will make 
certain editing operations much harder by increasing the context 
sensitivity of code.

Suppose I see code like the following:

   x = (a*a + b*b) / (1 - a*a - b*b)

and I realize I can improve efficiency by pulling out the subexpression:

   tem = a*a + b*b
   x = tem / (1 - tem)

Under this proposal, I would have to care whether tem had been 
(irrelevantly) used before or not and write the above differently 
depending on which.  Similarly I would also have to care if tem were 
(irrelevantly) used after and possibly revise the later code depending 
on whether it were also used previously.  What a bother!  This will make 
for more new bugs than the proposal might eliminate.

There really is some virtue to the simple-minded design most languages use.

Terry Jan Reedy




More information about the Python-ideas mailing list