Static Typing in Python

Dang Griffith google0 at lazytwinacres.net
Sun Mar 14 14:43:15 EST 2004


On Sat, 13 Mar 2004 14:59:42 +0000 (GMT), Premshree Pillai
<premshree_python at yahoo.co.in> wrote:

> --- Dang Griffith <google0 at lazytwinacres.net> wrote:
>> On Sat, 13 Mar 2004 07:07:50 +0000 (GMT), Premshree
>> Pillai
>> <premshree_python at yahoo.co.in> wrote:
>> 
>> > --- Jacek Generowicz <jacek.generowicz at cern.ch>
>> >Yes, I am aware that Python is dynamically typed,
>> and
>> >so is Perl, right? In Perl, we have the "use strict
>> >vars" pragma to force variable declaration. Is
>> there
>> >something like it in Python?
>> 
>> No, but you can use pychecker to get similar
>> results.
>> 
>> >Don't you think forced variable declaration is an
>> >important requirement in a language?
>> 
>> Not really.  Forced variable initialization is
>> what's important.
>> Unlike C, et al, and Perl, variables don't have a
>> default 
>> initial value.  If you try reference a variable that
>> hasn't been
>> initialized ("bound to a value", in python lingo),
>> python raises a
>> NameError exception.
>> 
>>     --dang
>> p.s.
>> I know technically Perl initializes to 'undef', but
>> it's magically
>> treated as 0 or an empty string, depending on
>> context, so the
>> effect is much the same.
>> -- 
>> http://mail.python.org/mailman/listinfo/python-list 
>
>Not forcing variable initialization does have its
>problems. Here's what I mean: http://www.livejournal.com/users/premshree/10624.html?thread=53376#t53376

Yes, I agree.  That is one reason I like Python.
It has forced variable *initialization*.  You cannot use a variable
that has not been initialized.  In fact, the act of initializing a
variable is what makes the variable exist.

I do not think forced *declaration* is important, except perhaps in
C/++/#/Java, Pascal, Ada, etc.  

I see the typo in the pseudo-code example.  PyChecker will catch that.
I typed in your code, converted it to Python, and ran pychecker on it:
    Warnings...
    bluesmoon.py:12: Local variable (my_varaible) not used

    --dang



More information about the Python-list mailing list