[Types-sig] changing variable types (was: Static typing considered HARD)

Greg Stein gstein@lyra.org
Mon, 6 Dec 1999 16:50:11 -0800 (PST)


On Sat, 4 Dec 1999, Uche Ogbuji wrote:
>...
> Also, I don't think I've _ever_ done anything as off-the-wall as
> "modifying the type of a variable in a function call or changing the
> __class__ of an object".  I hope this isn't anyone's benchmark of
> Python's dynamicism.

I think he means something like:

   names = { }
   for elem in whatever:
     names[extract_foo(elem)] = 1
   names = names.keys()

I've done this a number of times. It can be argued that using a single
name ("names") for a single semantic/concept is a good thing, despite the
fact that its type changes within the function. Introducing two names is
certainly clearer from a type standpoint, but I'd argue that a reader
doesn't care about *types*, but about what is happening (the semantics).

At least, that's how I rationalize the pattern :-)

Cheers,
-g

-- 
Greg Stein, http://www.lyra.org/