Article of interest: Python pros/cons for the enterprise
Nicola Musatti
Nicola.Musatti at gmail.com
Sat Feb 23 13:39:00 EST 2008
Paul Rubin wrote:
> 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.
>> int f(int n) { return n * 2; }
>> int g(int n) { return ( n * 2 ) + 1; }
>
> That is not a reasonable translation, since you've assumed the output
> of f and g are integers that don't need to be dynamically allocated.
> Maybe in the Python example, f and g and x and y are all bignums or
> matrices or something like that.
In my example I return a map by value just to show that it can be
generalized to more complex data types. This is not C: in C++ you can go
a long way without allocating dynamic memory explicitly. In my example
std::map and std::vector do it for me.
Cheers,
Nicola Musatti
--
Nicola.Musatti <at> gmail <dot> com
Home: http://nicola.musatti.googlepages.com/home
Blog: http://wthwdik.wordpress.com/
More information about the Python-list
mailing list