RAII vs gc (was fortran lib which provide python like data type)
Steven D'Aprano
steve+comp.lang.python at pearwood.info
Sat Jan 31 22:00:05 EST 2015
Sturla Molden wrote:
> Rustom Mody <rustompmody at gmail.com> wrote:
>
>> The case of RAII vs gc is hardly conclusive:
>>
>> http://stackoverflow.com/questions/228620/garbage-collection-in-c-why
>
> The purpose of RAII is not to be an alternative to garbage collection
> (which the those answers imply), but to ensure deterministc execution of
> setup and tear-down code. The Python equivalent of RAII is not garbage
> collection but context managers.
>
> Those answers is a testimony to how little the majority of C++ users
> actually understand about the language.
>
>
>
> A C++ statement with RAII like
>
> {
> Foo bar();
> // suite
> }
>
> is not equivalent to
>
> bar = Foo()
>
> in Python. It actually corresponds to
>
> with Foo() as bar:
> <suite>
Nice answer! I'm not qualified to tell whether you are right or not, but
what you say has the ring of truth about it.
--
Steven
More information about the Python-list
mailing list