From owner-freebsd-hackers Mon Jul 29 08:09:02 1996 Return-Path: owner-hackers Received: (from root@localhost) by freefall.freebsd.org (8.7.5/8.7.3) id IAA03140 for hackers-outgoing; Mon, 29 Jul 1996 08:09:02 -0700 (PDT) Received: from parkplace.cet.co.jp (parkplace.cet.co.jp [202.32.64.1]) by freefall.freebsd.org (8.7.5/8.7.3) with ESMTP id IAA03135 for ; Mon, 29 Jul 1996 08:08:56 -0700 (PDT) Received: from localhost (michaelh@localhost) by parkplace.cet.co.jp (8.7.5/CET-v2.1) with SMTP id PAA29597; Mon, 29 Jul 1996 15:08:41 GMT Date: Tue, 30 Jul 1996 00:08:41 +0900 (JST) From: Michael Hancock To: David Greenman cc: Poul-Henning Kamp , hackers@FreeBSD.ORG Subject: Re: kernel assertions In-Reply-To: <199607291401.HAA26854@root.com> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-hackers@FreeBSD.ORG X-Loop: FreeBSD.org Precedence: bulk On Mon, 29 Jul 1996, David Greenman wrote: > >In our code: > > void > > foo(char *buf, int i > > { > > ASSERT(buf,("foo(%p, %d): buf is zero",buf,i)); > > ... > > } > > Blech. Macros are evil unless they actually do something real to improve > the code. Please, let's NOT adopt this practice. They can reduce conceptual pollution. A conscientious programmer might integrate various checks into code that is trying to do something else and as a side-effect makes the code more complicated for readers and even compiler optimizers. Assertions are the most under-rated software engineering tool I can think of. If you want more information, stringify the expression in the assertion failure message or add a description parameter. At least give us the benefit of the doubt and try applying this to some random sample of code to see the difference it makes. I can think of 3 types of programmers who don't use assertions: 1) The god who writes all the code with zero bugs and doesn't need assertions. 2) The conscientious defensive programmer who integrates a lot of code checks in his code. The code has lots of nested structures and is complicated to read. 3) The programmer who gives up on the writing the checks because it's hell. His code is probably the source of very hard to find bugs. Assertions are simple to use and let's you write code for the problem at hand. There's no question as to where the responsibilities of the caller or callee lie. Mike Hancock