Re: Literate style, making code more readable or going overboard?

George Dinwiddie <[email protected]> Wed, 10 Feb 2010 04:30:06 -0500
Newsgroups gmane.comp.programming.refactoring
Organization iDIA Computing, LLC
Message-ID <[email protected]>
Hi, Markus,

Markus Knittig wrote:
> George Dinwiddie wrote:
>> 	if (!adminUsers.isEmpty()) {
>> 	    ...
>> 	}
> 
> Not exactly topic related but are there any specific reason why you 
> prefer this instead of:
> if (adminUsers.size() > 0) {
>      ...
> }
> ?

I think it communicates my intent better.  The predicate isn't really 
concerned with size beyond whether it contains something.  The count of 
items is irrelevant detail.

Last I looked, isEmpty() just looks at the size in ArrayList, but I can 
imagine a situation where a collection might be able to evaluate 
isEmpty() a lot cheaper than size().

> Cause I learned that you should avoid negotiating conditions.

What does that mean?  Do you mean "negating?"  And why?

  - George

-- 
  ----------------------------------------------------------------------
   * George Dinwiddie *                      http://blog.gdinwiddie.com
   Software Development                    http://www.idiacomputing.com
   Consultant and Coach                    http://www.agilemaryland.org
  ----------------------------------------------------------------------



------------------------------------

Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/refactoring/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/refactoring/join
    (Yahoo! ID required)

<*> To change settings via email:
    [email protected] 
    [email protected]

<*> To unsubscribe from this group, send an email to:
    [email protected]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/