From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id TAA05650; Wed, 8 May 2002 19:12:11 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id TAA05559 for ; Wed, 8 May 2002 19:12:11 +0200 (MET DST) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id g48HC4D28610; Wed, 8 May 2002 19:12:04 +0200 (MET DST) Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id TAA04979; Wed, 8 May 2002 19:12:03 +0200 (MET DST) From: Pierre Weis Message-Id: <200205081712.TAA04979@pauillac.inria.fr> Subject: Re: [Caml-list] Naming conventions In-Reply-To: <200205081359.g48DxNO09861@sarg.ryerson.ca> from Dave Mason at "May 8, 102 09:59:23 am" To: dmason@sarg.ryerson.ca (Dave Mason) Date: Wed, 8 May 2002 19:12:03 +0200 (MET DST) Cc: caml-list@inria.fr X-Mailer: ELM [version 2.4ME+ PL28 (25)] MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk [...] > But, the original question was about objects. In Java there is a > style that is fairly convenient, whereby mutators for objects return > the object itself instead of void (unit). This allows doing: [...] Oh, please, no! We had once these style of primitives in Caml and found it really error prone: you just confuse procedures and functions! A procedure is called for its side effects, hence it does not return any meaningful value, and hence it reflects this fact in its return type that should be unit. Thanks to this convention, there is a special warning to help the programmer not to forget an argument to a procedure call inside a sequence of side-effects: if f has type int -> int -> unit and you compile the sequence begin f 1; print_newline () end then you will have a warning for the incomplete call f 1 (telling you that this expression should have type unit). If your procedures wrongly return a value which is not unit, then you will have warnings everywhere; hence, you will disable warnings; hence, you will miss partially applied procedure calls. When programming in the large, such silently ignored side-effects are a nightmare to find out, particularly if the given procedure has a lot of arguments (imagine forgetting just the last argument to mult_nat, that is just providing eight out of nine of the required arguments! It is easy to find if the compiler points it out for you, otherwise you can read the program over and over again without noticing the missing arg). So no. This ``fairly convenient style'' is not your friend; it is in fact as convenient as programming without a type-checker: seemingly ``cool'' at the beginning, but really harder in the long run. Pierre Weis INRIA, Projet Cristal, Pierre.Weis@inria.fr, http://pauillac.inria.fr/~weis/ ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners