Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Markus Mottl <mottl@miss.wu-wien.ac.at>
To: Gerd.Stolpmann@darmstadt.netsurf.de
Cc: caml-list@inria.fr (OCAML)
Subject: Re: small code problem
Date: Sun, 11 Jul 1999 20:23:46 +0100 (MET DST)	[thread overview]
Message-ID: <199907111823.UAA14351@miss.wu-wien.ac.at> (raw)
In-Reply-To: <99070915534909.28040@schneemann> from "Gerd Stolpmann" at Jul 9, 99 03:56:31 pm

> Programming can be seen as a transformation of conditions. For example:
> 
> 	if Array.length Sys.argv >= 1 then do_this else do_that
> 
> You can reason about this statement, and you come to the (trivial) result that
> the length of the array is >= 1 just before 'do_this' is evaluated. Because
> of this, 'do_this' can be something like 'Sys.argv.(0)', and evaluation is
> always successful. It is important to consider this as a kind of reasoning
> which is done by the programmer and which might be errorneous (it is often not
> so trivial). Of course, the interpreter checks again that the array is big
> enough, but I would prefer another view: Not the array size is checked, but
> what the programmer thinks about the array size. This has the advantage that
> Invalid_argument is an indicator that I came to the wrong conclusions when I
> wrote the program. -- In the literature this is known as "defensive
> programming", it often leads to much more stable programs.

I also think that checking conditions by catching exceptions leads to a
wrong style of programming: if you catch such exceptions around somewhat
bigger blocks, you might catch one which was raised in a completely
different context than you had imagined.  But your program would continue
as if everything were ok, possibly leading to misbehaviour in a program
part far away from the point where the exception was raised/caught. Using
explicit checks before evaluation of "dangerous" expressions is much
safer and more transparent.

Best regards,
Markus

-- 
Markus Mottl, mottl@miss.wu-wien.ac.at, http://miss.wu-wien.ac.at/~mottl




  reply	other threads:[~1999-07-12 18:26 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <199907090927.KAA09195@toy.william.bogus>
1999-07-09 13:56 ` Gerd Stolpmann
1999-07-11 19:23   ` Markus Mottl [this message]
1999-07-08 18:23 Damien Doligez
  -- strict thread matches above, loose matches on Subject: below --
1999-07-02 22:30 <Brad Knotwell
1999-07-08  4:56 ` Markus Mottl
1999-07-08 22:49 ` Gerd Stolpmann
1999-07-09  0:27   ` <Brad Knotwell
1999-07-09  1:37     ` Fabrice Le Fessant

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=199907111823.UAA14351@miss.wu-wien.ac.at \
    --to=mottl@miss.wu-wien.ac.at \
    --cc=Gerd.Stolpmann@darmstadt.netsurf.de \
    --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