From owner-freebsd-hackers Thu Feb 26 17:41:29 1998 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id RAA17358 for freebsd-hackers-outgoing; Thu, 26 Feb 1998 17:41:29 -0800 (PST) (envelope-from owner-freebsd-hackers@FreeBSD.ORG) Received: from parkplace.cet.co.jp (parkplace.cet.co.jp [202.32.64.1]) by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id RAA17332 for ; Thu, 26 Feb 1998 17:41:05 -0800 (PST) (envelope-from michaelh@cet.co.jp) Received: from localhost (michaelh@localhost) by parkplace.cet.co.jp (8.8.8/CET-v2.2) with SMTP id BAA01347; Fri, 27 Feb 1998 01:40:18 GMT Date: Fri, 27 Feb 1998 10:40:18 +0900 (JST) From: Michael Hancock To: Niall Smart cc: FreeBSD Hackers Subject: Re: cshort - speaking of new utilities In-Reply-To: Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG On Thu, 26 Feb 1998, Niall Smart wrote: > > int > > foobar(a) > > int a; > > REQUIRE(a > 0); > > ENSURE(retval < 100); > > Ugh, do you really use this precondition stuff? Sure. It beats writing specs and they're kept up to date. If you were really pedantic about it every time you looked at a piece of code without preconditions you would say, "Anything goes". This code is telling me that I can give it whatever I want as arguments. I do get lazy on the obvious stuff, but when things get complex you'd be amazed at how simple pre-conditions help. The pre-conditions are usually far more helpful than the post-conditions, but at least letting your consumers know very clearly what your code is supposed to guarantee is definitely a plus. Preprocess them away and you can actually reduce the amount of code you might otherwise have had. The reduction in code reduces complexity and saves your brain from hurting too much. Take a look at the code in, "Programming with Threads" by Steve Kleiman, Devang Shah, and Bart Smaalders for examples of how assertions and invariants are used. Writing complex reentrant code can really boggle your brain. Regards, Mike To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message