caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Stefan Monnier <monnier@iro.umontreal.ca>
To: caml-list@inria.fr
Subject: Re: exception safety / RAII ?
Date: Sat, 12 Mar 2005 17:54:24 -0500	[thread overview]
Message-ID: <87ekekeb9g.fsf-monnier+gmane.comp.lang.caml.inria@gnu.org> (raw)
In-Reply-To: <200503101652.01848.jon@ffconsultancy.com>

>> > However, provided you don't need to make any guarantees about when the
>> > file is  closed during the running of the program, I still think that
>> > implicitly closing a file (or deallocating an external resource) via the
>> > GC is not  sloppy coding. Indeed, this facility can be very useful and
>> > can eliminate an important class of run-time errors.
>> 
>> Can you give examples where it's useful?  I don't consider "not needing to
>> call `close' on line NNNN of my code" to be useful.

> OpenGL display lists from earlier in this thread.

Two problems with this example: it doesn't involve files AFAICT, and it's
not an example in any useful sense.  You'd need to describe the skeleton of
the code to explain why it's useful (rather than merely convenient).

>> Can you describe the "important class of runtime errors" that would be
>> supposedly eliminated?

> In that case, undefined rendering behaviour when a display list is executed
> after it has been incorrectly destroyed.  This could also wreck the OpenGL
> state and break rendering for the rest of the frame or even for the rest of
> the program.

[ Ignoring the fact that it still doesn't seem to involve files ] Are such
errors common (or difficult to diagnose/fix) enough that they deserve the
name "important class of runtime errors"? (genuine question: I know next to
nothing about OpenGL).

>> > In the case of files, yes.  More generally, this can be applied to all
>> > sorts of external resources where that is not true.
>> 
>> Might be: there's no way we can generalize.  I'm talking about files here.
>> Finalizers are great, but they shouldn't be used for files.

> Let me try another file-specific example then: Programs which save output
> at  some point during their execution.  From the users point of view,
> there is no  "visible" difference between having the program close the
> file as soon as  writing is complete and leaving it up to the GC to close
> the file a short  time afterwards (and before it completes).  I have many
> such programs.

You're arguing beside my point: I don't care whether there are cases where
using finalizers to close files doesn't hurt.  My point is both that there
are cases where they do hurt (even sometimes for the exact same code where
they didn't hurt in other circumstances), and that the added convenience of
not needing to explicitly close the file is insignificant.

So I'd like to see an example where the lack of a "file-close finalizer"
would make the code harder to write.

>> I'd also argue that they generally shouldn't be used for any "external
>> resource".  Though I wouldn't be surprised if there's a counter example
>> somewhere where I'd agree that finalizers are good solution for the
>> management of some particular kind of external resource in some
>> particular circumstance.
> Even if the external resource is memory?

I've already replied to this and even gave another example (CPU), so please
try something else.


        Stefan


  parent reply	other threads:[~2005-03-12 22:55 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-03-05 18:16 Michael Benfield
2005-03-05 18:44 ` [Caml-list] " Gerd Stolpmann
2005-03-07  0:03 ` Jon Harrop
2005-03-07  1:32   ` Stefan Monnier
2005-03-07  2:48     ` [Caml-list] " Brian Hurt
2005-03-07 13:30     ` Jon Harrop
2005-03-07 14:37       ` Stefan Monnier
2005-03-07 17:10         ` [Caml-list] " Jon Harrop
2005-03-08 13:07           ` Damien Doligez
2005-03-08 21:56           ` Oliver Bandel
2005-03-09 13:34             ` Damien Doligez
2005-03-09 14:48           ` Stefan Monnier
2005-03-09 16:19             ` [Caml-list] " Jon Harrop
2005-03-09 22:45               ` [Caml-list] Re: exception safety / RAII Oliver Bandel
2005-03-09 23:42                 ` Charles Forsyth
2005-03-10 14:33               ` exception safety / RAII ? Stefan Monnier
2005-03-10 16:52                 ` [Caml-list] " Jon Harrop
2005-03-11 14:46                   ` Michael Walter
2005-03-12 22:54                   ` Stefan Monnier [this message]
2005-03-07 15:21       ` Michael Walter
     [not found]         ` <200503071729.20117.jon@jdh30.plus.com>
2005-03-07 18:47           ` Michael Walter
2005-03-08  1:10             ` Jon Harrop
2005-03-08 22:19               ` Oliver Bandel
2005-03-08 22:53               ` Daniel Yokomizo
2005-03-09  1:21                 ` [Caml-list] " Jon Harrop
2005-03-09 13:21                 ` Damien Doligez
2005-03-08 11:33             ` [Caml-list] " Ville-Pertti Keinonen
2005-03-08 12:32               ` Richard Jones
2005-03-08 14:17                 ` Michael Walter
2005-03-08 18:28               ` Jon Harrop
2005-03-08 21:34                 ` Damien Doligez
2005-03-09 15:05                 ` Stefan Monnier
2005-03-09 22:30                   ` [Caml-list] " Marcin 'Qrczak' Kowalczyk
2005-03-10 14:20                     ` Stefan Monnier
2005-03-08 21:32       ` [Caml-list] " Oliver Bandel
2005-03-07  3:31   ` [Caml-list] " Michael Walter

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87ekekeb9g.fsf-monnier+gmane.comp.lang.caml.inria@gnu.org \
    --to=monnier@iro.umontreal.ca \
    --cc=caml-list@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).