Excellent tip Hugh - I missed that one myself.  But that formatting! 
Shouldn't the open brace...

<smack-myself-on-the-hand>
    Right! Don't go there!
</smack-myself-on-the-hand>

Rowland

> I realize that I am getting off your original topic of efficiency an into
> the area of coding style, but for what it's worth, I would do one more
> thing to make the code considerably more resilient.
>
> I ALWAYS put code that is dependent on an if statement in a block with
> braces.
>
> String formcomments = attr.getFormComments();
> if (formcomments == null)
> {    formcomments = "";
> }
>
> Later, you may want to add more code that is part of the if logic, such as
> a debugging statement or a return.
>
> If you add a new statement and forget to add braces, either the original
> statement or the new statement will be executed unconditionally.
>
> This has bitten me more than once. If you are in a hurry, it's easy to
> miss the fact that the if statement and the one that follows are related
> at all.
>
> I think it worth the extra line to include the braces.
>
> Hugh
>
>
> At 03:13 PM 7/22/2004, you wrote:
>
>>My preference always goes to the easiest to read...I would write:
>>
>>String formcomments = attr.getFormComments();
>>if (formcommets == null)
>>    formcomments = "";
>>
>>IMO, it is more obvious that the result (formcomments) will be assigned
>>the value of attr.getFormComments(), unless the special case (null)
>>is encountered.
>>
>>
>>
>>C
>>
>>
>>disclaimer: This advice is worth exactly what you paid for it...maybe
>> less.
>>
>>
>>Tony Spencer wrote:
>>>Which of these examples is better practice or does not not really
>>> matter?
>>>Example 1:
>>>String formcomments = attr.getFormComments();
>>>formcomments = (formcomments == null) ? "" : formcomments;
>>>
>>>Example 2:
>>>String formcomments = (attr.getFormComments()== null) ? "" :
>>>attr.getFormComments();
>>
>>
>>--
>>-------------------------------------------------------------------------
>>Chris Merrill                  |  http://www.webperformanceinc.com
>>Web Performance Inc.           |  http://www.webperformancemonitoring.net
>>
>>Website Load Testing, Stress Testing, and Performance Monitoring Software
>>-------------------------------------------------------------------------
>>
>>
>>_______________________________________________
>>Juglist mailing list
>>[EMAIL PROTECTED]
>>http://trijug.org/mailman/listinfo/juglist_trijug.org
>>
>>
>>
>>
>>---
>>Incoming mail is certified Virus Free.
>>Checked by AVG anti-virus system (http://www.grisoft.com).
>>Version: 6.0.725 / Virus Database: 480 - Release Date: 7/19/2004
>
>
> ---
> Outgoing mail is certified Virus Free.
> Checked by AVG anti-virus system (http://www.grisoft.com).
> Version: 6.0.725 / Virus Database: 480 - Release Date: 7/19/2004
> _______________________________________________
> Juglist mailing list
> [EMAIL PROTECTED]
> http://trijug.org/mailman/listinfo/juglist_trijug.org
>


_______________________________________________
Juglist mailing list
[EMAIL PROTECTED]
http://trijug.org/mailman/listinfo/juglist_trijug.org

Reply via email to