Typing system vs. Java

Alex Martelli aleaxit at yahoo.com
Tue Jul 31 12:33:13 EDT 2001

"Christian Tanzer" <tanzer at swing.co.at> wrote in message
news:mailman.996592198.30711.python-list at python.org...
> poor programming on my part, but I can't even think how one would type a
> function like say:
>    def f(zs): return reduce( lambda x, y: x + y, zs )

Genericity (templates in C++) this is not a problem -- you get one
instance of `f` for each type `zs` you happen to apply `f` to.

Disclaimer: C++ templates don't allow different return types for such
functions, but that's a restriction of C++, not of genericity. IIRC,

Beg pardon?

template<class A, class B>
A myfunction(const B& b)
    return b;

Maybe you mean that C++ doesn't *automatically INFER* A when
you just call myfunction(something)?  But, you CAN partially
specify myfunction<int>(something) [or, of course, totally
specify myfunction<int,double>(something)], if you have a
standard-compliant C++ compiler.

Back to Python -- programming in Python has always felt to
me a *LOT* like generic programming (e.g. with C++ templates)
in so many ways... of course, I was "steeped" in C++ generics
well before I met Python, so that may help explain this:-).

But, really, the only significant difference seems to me to
be that C++ instantiates its generics at compile-time (less
flexibility, some more syntax cruft, better runtime speed)
while Python works in a fully dynamic way, at runtime (some
errors are diagnosed a bit later, speed is not so great,
syntax is very lightweight and flexibility is nonpareil).

They're still very subjectively similar programming mindsets...
*signature-based polymorphism* dominates in either case!

Alex (Brainbench MVP for C++)

More information about the Python-list mailing list