Ruby Impressions
Alex Martelli
aleax at aleax.it
Tue Jan 15 09:08:53 EST 2002
"Phil Tomson" <ptkwt at shell1.aracnet.com> wrote in message
news:EOH08.4836$WM6.1207331 at e420r-atl1.usenetserver.com...
...
> do for them. I recently attended a talk on generic programming which
> ended up being a talk on C++ templates.
Makes sense, as they're by far the most widespread implementation
of generic programming today (not by accident A. Stepanov, the guru
of generic programming, designed the STL in C++ after earlier
versions in Ada and other languages).
> Throughout the whole thing I kept
> thinking that generic programming comes naturally in a dynamic language,
Well, *almost* -- it depends on what kind of dispatching you get in that
"dynamic language". Try Perl, you'll be a bit disappointed; fundamental
types aren't polymorphic (lists with strings with numbers with hashes...).
Python only proves disappointing to people used to multi-dispatching, and
(given Dylan's unfortunate lack of success so far) there are not all
that many of those.
Still, it's true that programming Python feels A LOT like programming
C++ templates -- as a C++ expert, that's the very strong feeling I
got when I discovered Python.
> you don't have to go through all the contortions that are needed in a
> compile-time, statically-typed language like C++.
The "contortions" in C++ templates are only syntactical issues. The
semantics are those of smooth, seamless signature-based polymorphism,
just as in Python. Of course in either case it's quite possible to
throw spanners into the works by typetesting -- start coding
if type(x) == type(y):
and you're well on the way to ruin.
> OOP in general 'feels'
> very different in a dynamically typed language vs a statically typed one.
> Polymorphism, for example, seems much easier to really use to your
> advantage in a dynamically typed language.
Yes, as long as [a] you're satisfied with polymorphism constrained to
happen on one argument and possibly via very specific interfaces on
other arguments, [b] you don't typecheck (but trying to convince SOME
programmers to give up the latter, destructive practice is definitely
an uphill effort).
Alex
More information about the Python-list
mailing list