caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: David Rajchenbach-Teller <David.Teller@univ-orleans.fr>
To: orbitz@ezabel.com
Cc: Gerd Stolpmann <info@gerd-stolpmann.de>,
	rossberg@mpi-sws.org, caml-list@inria.fr
Subject: Re: [Caml-list] Scoped Bound Resource Management just for C++?
Date: Thu, 10 Feb 2011 09:10:11 +0100	[thread overview]
Message-ID: <AC5015DD-0C9F-4F7E-A06D-9CE106E164E8@univ-orleans.fr> (raw)
In-Reply-To: <25000DA4-042A-437D-8082-10C70E1C740F@ezabel.com>


Well, that depends -- keep in mind that I'm discussing one specific instance, that of closing streams and ensuring that they are correctly flushed, in the right order.

* users manually closing the stream
keeping things safe is essentially the same issue in OCaml and C++;

* downstream stream being closed
keeping things safe is essentially the same issue in OCaml and C++, but the garbage-collector does make things easier in OCaml;

* garbage-collection/deallocation
Probably easier in C++, as long as you keep to the small subset of C++ in which users discipline themselves to simple resource allocation/finalization idioms.
Suddenly much harder if your users can heap-allocate or pass by reference for the purpose of sharing between distinct scopes (which, in my experience, is the kind of thing you want to do as soon as your library is powerful enough).

* abrupt (but non-segfault) termination of the program, say a thread killing the whole process 
Now, I'm not sure how one would implement this in C++. I tend to believe it's easier in OCaml, as judicious use of [at_exit] and weak references lets you register behaviors that will only be triggered if garbage-collection hasn't taken place by the time the program exits.



Now, of course, we touch another issue: the way I see it, C++ is not just one language, but a whole collection of languages with interoperability. Things that make perfect sense and are completely safe if you limit yourself to some idioms suddenly become the stuff of segfaultish nightmares if you attempt to integrate them in a project which has been written with a distinct set of axioms. I'd call this a clear win by OCaml :)

Cheers,
 David

On Feb 9, 2011, at 6:54 PM, orbitz@ezabel.com wrote:

> Do they appear in C++?  I would a dtor takes care of that for you when it comes to streams.



  parent reply	other threads:[~2011-02-10  8:10 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-02-08 23:57 orbitz
2011-02-09  0:46 ` Guillaume Yziquel
2011-02-09  0:48 ` Jacques Garrigue
2011-02-09  6:25 ` dmitry grebeniuk
2011-02-09 12:01 ` rossberg
2011-02-09 15:15   ` orbitz
2011-02-09 16:14     ` Gerd Stolpmann
2011-02-09 16:52       ` David Rajchenbach-Teller
2011-02-09 17:54         ` orbitz
2011-02-09 21:50           ` Jon Harrop
2011-02-10  8:10           ` David Rajchenbach-Teller [this message]
2011-02-10 10:39     ` Guillaume Yziquel
2011-02-10 10:59       ` Guillaume Yziquel
2011-02-09 19:11   ` Florian Weimer
2011-02-09 20:10     ` Andreas Rossberg
2011-02-09 20:45       ` Florian Weimer
2011-02-09 21:12         ` Andreas Rossberg
2011-02-10 21:31           ` Florian Weimer
2011-02-09 18:03 ` Jon Harrop
2011-02-09 20:47 ` Norman Hardy
2011-02-09 21:00   ` Gabriel Scherer

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=AC5015DD-0C9F-4F7E-A06D-9CE106E164E8@univ-orleans.fr \
    --to=david.teller@univ-orleans.fr \
    --cc=caml-list@inria.fr \
    --cc=info@gerd-stolpmann.de \
    --cc=orbitz@ezabel.com \
    --cc=rossberg@mpi-sws.org \
    /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).