From ok@atlas.otago.ac.nz Sun Oct 28 23:21:52 2001
Received: from atlas.otago.ac.nz (atlas.otago.ac.nz [139.80.32.250])
	by swi.psy.uva.nl (8.11.2/8.11.2) with ESMTP id f9SMLot12387;
	Sun, 28 Oct 2001 23:21:50 +0100 (MET)
Received: (from ok@localhost)
	by atlas.otago.ac.nz (8.9.3/8.9.3) id LAA173317;
	Mon, 29 Oct 2001 11:21:48 +1300 (NZDT)
Date: Mon, 29 Oct 2001 11:21:48 +1300 (NZDT)
From: "Richard A. O'Keefe" <ok@atlas.otago.ac.nz>
Message-Id: <200110282221.LAA173317@atlas.otago.ac.nz>
To: jan@swi.psy.uva.nl, pmoura@noe.ubi.pt
Subject: Re: [SWIPL] Type error vs. silent failure
Cc: prolog@swi.psy.uva.nl, salzer@logic.at

Paulo Moura <pmoura@noe.ubi.pt> wrote:
	Always doing argument checking for library predicates is probably 
	overkill for many applications.

I disagree.  There is certainly a practical question about HOW MUCH
checking is a good idea.  For example, if you have a library package
that is supposed to implement binary search trees, it would be a bad
idea to check the tree argument in full every time, because that would
spoil the logarithmetic cost that is the whole reason for using such trees.

In the absence of a static type system, error reports at run time are
important.  A reasonable level of checking is one of the most useful
services a library implementor can provide for the library users.

When you are determined to do a workmanlike job of error reporting,
it's amazing what little crannies you can find to wedge a useful amount
of error detection into without much overhead.  Certainly, whenever you
already have an if->then;else, there's a fair chance you can squeze an
error check in.

	I have been playing around with the idea of defining two sets of
	library objects:  one for debugging or critical applications
	containing error-checking code for every predicate and another
	version with that safe belt removed for applications that do not
	need/want error-checking.  The two versions of the objects will
	share the same name.  The programmer or the application will
	choose the version to load (possibly with some compiler flag).
	
This has been compared to wearing a lifejacket when the boat is on the
slip-way, but taking it off when the boat is in the water.  It is a
proven Bad Idea.

The machine on my desk is 150MHz, and it's only a few years old.
1.5GHz machines are now in the shops for less money.
Removing error checking code in the name of speed is a perverse
way of wasting development time.
	

