does lack of type declarations make Python unsafe?

Aahz aahz at pythoncraft.com
Thu Jun 19 13:49:32 EDT 2003


In article <6amIa.113863$pR3.2478359 at news1.tin.it>,
Alex Martelli  <aleax at aleax.it> wrote:
>Aahz wrote:
>> In article <pNfIa.206219$g92.4232233 at news2.tin.it>,
>> Alex Martelli  <aleax at aleax.it> wrote:
>>>
>>>In Python one generally identifies (just as informally) a container as
>>>"an object which has a length" (using "length", perhaps a suboptimal
>>>choice of wording, to mean "number of items currently contained") and
>>>simultaneously express both 'c is a container' and 'that container is
>>>not empty' by
>>>
>>>    assert len(c)
>> 
>> Hmmmm....  I would only do that for a sequence.  From my POV, classes,
>
>I can't believe one could find ANY sensible objection to "doing that"
>(checking len(c)) for a dictionary nor for a set.  Either your nitpick
>is very poorly expressed (something that should be particularly carefully
>avoided when nitpicking) or it just makes no sense whatsoever to me.

My nitpick was actually that your use of "container" was too specific
for Python (see below); my comment about len(c) was just a aside about my
use of Python, with an implied comment that len(c) doesn't work directly
with classes and modules.

You're correct, of course, that there is no intrinsic objection to using
len(c) with a dict/set.

>> class instances (even those not implementing any special methods), and
>> modules all serve as containers for the purpose of determining what an
>> appropriate "container object" is for any particular program.
>
>You may indeed choose to call a class (&c) "a container", because it
>does contain some things, just as some (e.g.) C programmer might choose
>to call a struct "a container" for the same reason.  It's simply not
>the common definition used in computer science (cfr. for example
>http://www.research.att.com/sw/tools/cdt/ ,
>http://www.xemacs.org/Documentation/packages/html/elib_3.html , &c).

That's not why I say that.  I say it because classes and modules are in
many ways thin wrappers around dicts, and in some cases the syntactic
advantages of classes/modules make them more appropriate containers, even
though one is functionally using them as dicts.  Consider the standard
advice to use modules as singletons, for example.
-- 
Aahz (aahz at pythoncraft.com)           <*>         http://www.pythoncraft.com/

"If you don't know what your program is supposed to do, you'd better not
start writing it."  --Dijkstra




More information about the Python-list mailing list