Strong/weak typing
Jorgen Grahn
grahn+nntp at snipabacken.se
Sun Aug 3 16:28:20 EDT 2008
On Fri, 01 Aug 2008 22:47:04 -0400, Mel <mwilson at the-wire.com> wrote:
> MartinRinehart at gmail.com wrote:
>
>> I'm writing Python as if it were strongly typed, never recycling a
>> name to hold a type other than the original type.
>>
>> Is this good software engineering practice, or am I missing something
>> Pythonic?
>
> Nothing wrong with what you're doing. I've never come up with a really
> convincing reason to recycle names. Possibly something that follows the
> evolution of the data:
>
> middle_name = raw_input ('Name?')
> middle_name = middle_name.split()
> middle_name = middle_name[1]
>
> It works, but I don't like it enough to actually use it.
I don't like that there are two lines where 'middle_name' isn't
actually a middle name. It confuses me, even though I know that
everything is ok after the third line.
I reuse names though, mostly because I don't want to invent additional
names which would feel "overburdened". I like this example better:
months = range(1, 13)
# do something with the months-as-numbers list,
# and then:
months = [ monthname(x) for x in months ]
# do something where we only need the names
Your comment "something that follows the evolution of the data"
applies here. It's the same data, but refined to a more usable form.
It also kills off an object which I have decided I will not need
further down, so it kind of documents that decision.
I only do this very locally, like in a simple function.
/Jorgen
--
// Jorgen Grahn <grahn@ Ph'nglui mglw'nafh Cthulhu
\X/ snipabacken.se> R'lyeh wgah'nagl fhtagn!
More information about the Python-list
mailing list