Return-Path: Delivered-To: apmail-directory-dev-archive@www.apache.org Received: (qmail 87184 invoked from network); 9 Jun 2010 08:33:16 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 9 Jun 2010 08:33:16 -0000 Received: (qmail 81713 invoked by uid 500); 9 Jun 2010 08:33:16 -0000 Delivered-To: apmail-directory-dev-archive@directory.apache.org Received: (qmail 81562 invoked by uid 500); 9 Jun 2010 08:33:15 -0000 Mailing-List: contact dev-help@directory.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Apache Directory Developers List" Delivered-To: mailing list dev@directory.apache.org Received: (qmail 81555 invoked by uid 99); 9 Jun 2010 08:33:15 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 09 Jun 2010 08:33:15 +0000 X-ASF-Spam-Status: No, hits=2.2 required=10.0 tests=FREEMAIL_FROM,HTML_MESSAGE,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of akarasulu@gmail.com designates 209.85.161.50 as permitted sender) Received: from [209.85.161.50] (HELO mail-fx0-f50.google.com) (209.85.161.50) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 09 Jun 2010 08:33:09 +0000 Received: by fxm1 with SMTP id 1so4503058fxm.37 for ; Wed, 09 Jun 2010 01:32:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:sender:received :in-reply-to:references:date:x-google-sender-auth:message-id:subject :from:to:content-type; bh=AfMD7M5ARK9h7eIqhu3u6aJSMJAnOdcy4xjRQupqK2I=; b=PGZTZjRQXcksaCI5U7YRCUTLwWMiAoavsQIU7jgdtwcQaKmZzY/J/inYc2PoteTrFA YgHKgVqyFZmm+eEbLZtfR1vJq/tFwTq+Y+BN2R+2rEfBZrLbelh6ikIPX5/SOM18OKg/ VDCfeZVc/mE9nx0rF7pxfYRuxJI+Hu9v2HePQ= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:content-type; b=o1Fl3QoYIHGQssiiZem3fFk97DovjT0KukD/NSa2ocEY6e5SCIkZNo1pObKGTG4bzt XGW7RUOEhDgBwVaO8Ym01w3GjeiJGiNf4L83JtHwP4egJGC+JYc3zh8Lsse/eiz7mNEO cg54wPbRogV6jKpk0FRnN9qwbHgPqPeJdMp3I= MIME-Version: 1.0 Received: by 10.239.163.67 with SMTP id o3mr1404486hbd.39.1276072368761; Wed, 09 Jun 2010 01:32:48 -0700 (PDT) Sender: akarasulu@gmail.com Received: by 10.239.183.81 with HTTP; Wed, 9 Jun 2010 01:32:48 -0700 (PDT) In-Reply-To: <609A6086-AA46-463E-A5F9-7D63AFAA7A92@toolazydogs.com> References: <4C08D23D.8060803@gmail.com> <4C08ED1D.4080403@apache.org> <609A6086-AA46-463E-A5F9-7D63AFAA7A92@toolazydogs.com> Date: Wed, 9 Jun 2010 11:32:48 +0300 X-Google-Sender-Auth: l4JxMPJX0xUDfscQSsMW7odtlGM Message-ID: Subject: Re: Should we use assert ? From: Alex Karasulu To: Apache Directory Developers List Content-Type: multipart/alternative; boundary=001485f20c543f6a25048894c083 X-Virus-Checked: Checked by ClamAV on apache.org --001485f20c543f6a25048894c083 Content-Type: text/plain; charset=ISO-8859-1 On Fri, Jun 4, 2010 at 4:08 PM, Alan D. Cabrera wrote: > > On Jun 4, 2010, at 5:10 AM, Stefan Seelmann wrote: > > > Emmanuel Lecharny wrote: > >> Hi guys, > >> > >> currently (and probably because nobody uses them, due to some Java 1.3 > >> habits we have), we don't use asserts to do simple things like checking > >> methods parameters (pre-conditions). > >> > >> Should we start using them ? > > > > I never used them before. > > > > For me assert is a bit magic because they are disabled at runtime and > > the assert statement isn't evaluated unless they are enabled. I prever > > to throw a IllegalArgumentException instead. > > I like asserts because they have the dual function of performing useful > sanity checking when turned on and also provide implicit documentation to > other developers as to what my fundamental assumptions are when I designed > my code. Take for example > > assert Thread.holdsLock(foo) : "I should be protected before you > call me"; > > This is a nice bit of code that explains my assumptions to other developers > when they use/extend my code with the added benefit that it gets turned off > once the code is deployed in production. > > Slavish use of asserts can lead to trouble; they are not a panacea. > Frontline argument and state checking at the client API end should never > use asserts for obvious reasons. However, performing the same kind of heavy > weight checking in my internal classes where I have complete control is a > bit of overkill; here asserts fit nicely. They also serve to warn the > developer that they are now troweling inside the bowels of a codebase. > > Just my 2 cents. > > Alan you make very good points. I don't think we should be using asserts for API semantic checks nor going wild with it but your subtle usage to show correctness to readers of the code is very important. Seelmann's points are also solid as well. I would rather use the proper IAE in conjunction with the proper parameter checks. This falls in line with Alan's comments. I'd like to see Alan's approach while writing code to help readers understand. Plus it has value when assertion checking is enabled during tests. My 2 cents. -- Alex Karasulu My Blog :: http://www.jroller.com/akarasulu/ Apache Directory Server :: http://directory.apache.org Apache MINA :: http://mina.apache.org To set up a meeting with me: http://tungle.me/AlexKarasulu --001485f20c543f6a25048894c083 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
On Fri, Jun 4, 2010 at 4:08 PM, Alan D. Cabrera = <list@toolazyd= ogs.com> wrote:

On Jun 4, 2010, at 5:10 AM, Stefan Seelmann wrote:

> Emmanuel Lecharny wrote:
>> Hi guys,
>>
>> currently (and probably because nobody uses them, due to some Java= 1.3
>> habits we have), we don't use asserts to do simple things like= checking
>> methods parameters (pre-conditions).
>>
>> Should we start using them ?
>
> I never used them before.
>
> For me assert is a bit magic because they are disabled at runtime and<= br> > the assert statement isn't evaluated unless they are enabled. I pr= ever
> to throw a IllegalArgumentException instead.

I like asserts because they have the dual function of performin= g useful sanity checking when turned on and also provide implicit documenta= tion to other developers as to what my fundamental assumptions are when I d= esigned my code. =A0Take for example

=A0 =A0 =A0 =A0assert Thread.holdsLock(foo) : "I should be protected = before you call me";

This is a nice bit of code that explains my assumptions to other developers= when they use/extend my code with the added benefit that it gets turned of= f once the code is deployed in production.

Slavish use of asserts can lead to trouble; they are not a panacea. =A0Fron= tline argument and state checking at the client API end should never use as= serts for obvious reasons. =A0However, performing the same kind of heavy we= ight checking in my internal classes where I have complete control is a bit= of overkill; here asserts fit nicely. =A0They also serve to warn the devel= oper that they are now troweling inside the bowels of a codebase.

Just my 2 cents.


Alan you make very= good points. I don't think we should be using asserts for API semantic= checks nor going wild with it but your subtle usage to show correctness to= readers of the code is very important.

Seelmann's points are also solid as well. I would r= ather use the proper IAE in conjunction with the proper parameter checks. T= his falls in line with Alan's comments.

I'= d like to see Alan's approach while writing code to help readers unders= tand. Plus it has value when assertion checking is enabled during tests.=A0=

My 2 cents.
=A0
--
Alex Karasu= lu
My Blog :: http://www.j= roller.com/akarasulu/
Apache Directory Server :: http://directory.apache.org
Apache MINA :: http://mina.apache.org
To set up a meeting with me:
http://tungle.me/AlexKarasulu
--001485f20c543f6a25048894c083--