Article of interest: Python pros/cons for the enterprise
Paul Rubin
http
Sat Feb 23 19:01:42 EST 2008
Nicola Musatti <Nicola.Musatti at gmail.com> writes:
> >>> a = [f(x) + g(y) for x,y in izip(m1, m2) if h(x,y).frob() == 7]
> [...]
> > There you replace one line of code with 40+ lines to get around the
> > absence of GC. Sounds bug-prone among other things.
>
> Come on, you didn't define f, g, izip, h or frob either. It's more
> like 5 to one. Furthermore your code is more compact due to the
> existence of list comprehensions, not because of GC. Had you written a
> loop the difference would be smaller.
No I don't need a loop if I don't use the listcomp. I could say
a = map(lambda x,y: f(x)+g(y), ifilter(lambda x,y: h(x,y).frob==7,
izip(m1, m2)))
the listcomp is basically syntax sugar for that.
The issue here is that Python is simply more expressive than C++,
which doesn't support creation of higher order functions like that.
However, one of the consequences of programming in this style is
you allocate a lot of temporary objects which best managed by GC.
More information about the Python-list
mailing list