Article of interest: Python pros/cons for the enterprise

Chris Mellon arkanes at gmail.com
Fri Feb 22 10:56:05 EST 2008


On Fri, Feb 22, 2008 at 4:56 AM, Nicola Musatti
<nicola.musatti at gmail.com> wrote:
> On Feb 22, 12:24 am, Carl Banks <pavlovevide... at gmail.com> wrote:
>  > On Feb 21, 1:22 pm, Nicola Musatti <nicola.musa... at gmail.com> wrote:
>  >
>  > > There are other downsides to garbage collection, as the fact that it
>  > > makes it harder to implement the Resource Acquisition Is
>  > > Initialization idiom, due to the lack of deterministic destruction.
>  >
>  > That's not a downside: it's at least a wash.
>  >
>  > In C++ you manage memory and the language manages resources.  In
>  > Python you manage resources and the language manages memory.
>  >
>  > RAII is merely one way of minimizing complexity.  Garbage collection
>  > is another way.
>
>  In C++ memory is just another resource which you can handle just like
>  any other one, possibly using RAII. GC deals with memory very
>  reasonably, but makes it more complicate to deal with other resources.
>
There are many different kinds of resource and they have different
optimal handling techniques. Memory in particular is really easily
handled by GC - it's a resource that you can reclaim under pressure,
so deferring it's collection and release makes sense, and it's even
common these days for high quality GC to beat manual management in
performance (never mind correctness). Other kinds of resource are much
more timely, and require tight control over scopes, like mutexes and
other locks. RAII is fantastic for these sort of things. Shared but
limited resources like files work best with refcounting (closing a
file that something else holds a reference to is usually an error).

Optimally, you would have a language that provides all three in easy,
transparent ways. Python only provides two, but the first on is the
least important so Python manages at least a B. C++ provides all 3,
but importantly there's no language level enforcement of use, so you
can (and people do, and this is a common source of bugs) accidentally
bypass the mechanisms.

If I had to use C++ these days, I'd use D instead.



More information about the Python-list mailing list