I come not to bury C++, but to praise it...
Donn Cave
donn at u.washington.edu
Wed Jan 14 17:50:18 EST 2004
In article <100b266i0r70g86 at corp.supernews.com>,
claird at lairds.com (Cameron Laird) wrote:
...
> Great! *What* more? When I look at Python and C++, I see the
> former as having *stricter*, if more dynamic, typing, so I don't
> understand what advantage C++ has in this one regard apart from
> time-of-detection.
>
> I apologize, by the way, for writing "compile-type" where I
> intended "compile-time".
Oops, so that was only an accident! Well, I mean that
the semantics of types are different between C++ and
Python.
When we say Python has "dynamic typing", and C++ has
"static typing", I guess that's the generally accepted
way to describe what they do, but it makes it sound
like they're doing the same thing, only on a different
schedule. Of course they are not at all doing the same
thing. It might be more accurate to use a table, like
static dynamic
C++ yes no
Python no yes
Objective C yes yes
Python may have stricter dynamic typing than C++ has
static typing, but that's hard to quantify. On the
other hand, Python has no static typing at all. There
is no way to tell it ``this function must be applied
to a string and must return an int.'' If applied to
a list instead, there's a non-trivial chance it will
manage to do something absurd with it. If it returns
None under certain circumstances, there's a non-trivial
chance that value will be stashed away somewhere and
you'll later wonder where the heck that None came from.
Whether that's an advantage for C++ depends on 1) how
important you think that is, and 2) how well you think
C++ does it. Between those two, I think I'd have to
agree it isn't much of an advantage, but then I'm just
a hacker. Of course C++ is an easy target, but then
that's the nominal subject here.
Donn Cave, donn at u.washington.edu
More information about the Python-list
mailing list