Date: Fri, 27 Feb 1998 10:40:18 +0900 (JST) From: Michael Hancock <michaelh@cet.co.jp> To: Niall Smart <njs3@doc.ic.ac.uk> Cc: FreeBSD Hackers <Hackers@FreeBSD.ORG> Subject: Re: cshort - speaking of new utilities Message-ID: <Pine.SV4.3.95.980227102241.1028D-100000@parkplace.cet.co.jp> In-Reply-To: <E0y8161-00019s-00@oak71.doc.ic.ac.uk>
next in thread | previous in thread | raw e-mail | index | archive | help
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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.SV4.3.95.980227102241.1028D-100000>