From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Delivered-To: caml-list@yquem.inria.fr Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by yquem.inria.fr (Postfix) with ESMTP id D3880BC48 for ; Wed, 9 Mar 2005 08:29:34 +0100 (CET) Received: from first.in-berlin.de (dialin-145-254-065-041.arcor-ip.net [145.254.65.41]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id j297TXp5032372 for ; Wed, 9 Mar 2005 08:29:33 +0100 Received: by first.in-berlin.de (Postfix, from userid 501) id 847D2B56B3; Tue, 8 Mar 2005 22:56:21 +0100 (CET) Date: Tue, 8 Mar 2005 22:56:21 +0100 From: Oliver Bandel To: caml-list@yquem.inria.fr Subject: Re: [Caml-list] Re: exception safety / RAII ? Message-ID: <20050308215621.GD1877@first.in-berlin.de> References: <293072a520e3724a0497e6456a8675be@mac.com> <200503071330.49084.jon@jdh30.plus.com> <87oedvcypd.fsf-monnier+gmane.comp.lang.caml.inria@gnu.org> <200503071710.52544.jon@jdh30.plus.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <200503071710.52544.jon@jdh30.plus.com> User-Agent: Mutt/1.5.6i X-Miltered: at concorde with ID 422EA5DD.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; oliver:01 bandel:01 oliver:01 in-berlin:01 caml-list:01 ocaml:01 implicitly:01 finalizer:01 finalizer:01 subjective:01 subjective:01 lazy:01 lazy:01 programmer's:01 perl's:01 X-Spam-Checker-Version: SpamAssassin 3.0.2 (2004-11-16) on yquem.inria.fr X-Spam-Status: No, score=0.3 required=5.0 tests=DATE_IN_PAST_06_12, FORGED_RCVD_HELO autolearn=disabled version=3.0.2 X-Spam-Level: On Mon, Mar 07, 2005 at 05:10:52PM +0000, Jon Harrop wrote: > 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. [...] If we say "visible from an outer environment", then it is clear, that this is really unfunctional programming style. What you are suggesting here? ... => It's how to write programs that introduce side-effects in a statistical manner and hoping on some subjective likeliehoods that all works well for all the time. So, why are you using and promoting functional programming style (which yields to more safeness in programs), when on the other side you are layzy in programming? That is, where the difference is between lazy evaluation of a programming language and lazy programmer's habbits! Some people rely on Perl's reference counting and are happy without "use strict", and others rely on OCaml's Garbage Collector and are happy with "-unsafe"-option.... But be sure: to write good and reliable software means to rely on *nothing*! You can write crap software in *every* language, if you want to... ...and crap begins, where the programmer is to lazy to write good code. Good code menas: good readable/understandable/good documented, but also reliable because of "knowing what's going on", which means: prefer functional style, not imperative (and the reason is: imperative code has side-effects you can not always oversee and which yields to *stochastical* behaviour ---> that's the same problem, what you are introducing, when relying on the Garbage Collector instead of writing good code!). The advantages of FP will be diminished by your style of programming! It's like let const = ref 1 (* no likeliehood here *) let baviour_of_your_program = ..... (* something wired*) let _ = Random.self_init (); baviour_of_your_program const (Random.float 10000.0) Ciao, Oliver P.S.: I tried Random.float max_float and it seems to be always between 1. * 10^307 ... 1. * 10^308 Is this a problem of initialization, or a problem of the Random-algorithm, or a kind of strange (?) behaviour of a random walk?