Version française
Home     About     Download     Resources     Contact us    
Browse thread
exception safety / RAII ?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Jon Harrop <jon@j...>
Subject: Re: [Caml-list] Re: exception safety / RAII ?
On Monday 07 March 2005 14:37, Stefan Monnier wrote:
> > I very rarely have problems with this.
>
> Very rarely having problems with something can't save it from being
> a very bad practice.  Not explicitly closing your files is (in 99% of the
> cases) just sloppy coding.

If we're talking about programs which are expected to run for an arbitrary 
amount of time (servers, the top-level etc.) then yes.

However, many programs run for a short time and, in these cases, I believe 
that OCaml guarantees to close your files at least upon program termination, 
if not before. Therefore, I would say that implicitly deallocating external 
resources is not sloppy coding in general.

> Kinda like letting a GC finalizer close 
> your windows: when the effect is visible from outside the process it
> shouldn't be done in a finalizer.

The term "visible" in this context is subjective. People could look to see 
when you close your file, or they could make other measurements to determine 
whether or not you had deallocated an external resource, but unless this is 
likely to cause a problem I wouldn't worry.

In the case of closing windows, I agree that would be sloppy coding. If you 
were talking about resources which the window had required and which the 
window manager is not likely to run out of, I wouldn't call it sloppy coding.

In the case of lablGL not guaranteeing that OpenGL and context resources are 
deallocated in the proper order, this has never caused a problem for anyone 
AFAIK and it would be tricky to fix so I don't worry about. I'd like to fix 
it, yes, but it isn't at the top of my priority list because it doesn't cause 
a problem.

In the case of me implicitly deallocating OpenGL display lists, this is never 
likely to cause a problem in practice so I'll probably never have to worry 
about. A user could still determine that I don't deallocate them immediately 
though, so you could still say that it is "visible".

I also think that this discussion ties in with OCaml and soft real-time tasks. 
In theory, OCaml should not be good for such tasks because the GC could act 
unpredictably. In practice, I find that OCaml is perfectly good for soft 
real-time.

-- 
Dr Jon D Harrop, Flying Frog Consultancy Ltd.
Objective CAML for Scientists
http://www.ffconsultancy.com/products/ocaml_for_scientists