commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Gary Gregory" <ggreg...@seagullsoftware.com>
Subject RE: [lang] ArrayUtils.lastIndex
Date Wed, 13 Oct 2004 23:59:53 GMT
I think we are both on the same page as far as that we have a different
perspective on this one issue, which is quite fine. I appreciate the
discussion.

I agree with you on the Javadoc point. Even with Javadoc 1.4 which lets
you see the constant value on a special page or even lets you embed the
value, it is nice to have the "real" value show up.

I'll play around with an ArrayUtils.INDEX_NOT_FOUND and see what it
looks like...

Gary

> -----Original Message-----
> From: Stephen Colebourne [mailto:scolebourne@btopenworld.com]
> Sent: Wednesday, October 13, 2004 14:26
> To: Jakarta Commons Developers List
> Subject: Re: [lang] ArrayUtils.lastIndex
> 
> My argument is that -1 is *such* a well-known value for not found that
> doesn't need to be defined as a constant. Sun doesn't define it as a
> constant in String or List for example. Nor does it define the empty
> string.
> 
> It depends on whether you in your calling code want to write:
>   if (ArrayUtils.indexOf(array, obj) == -1) {
>   }
> or
>   if (ArrayUtils.indexOf(array, obj) == ArrayUtils.INDEX_NOT_FOUND) {
>   }
> 
> I prefer the former, you appear to prefer the latter. There is no
right or
> wrong answer here, hence my -0, not a -1 to the proposal.
> 
> However I will -1 if the javadoc of the method is changed to say
> "returns the constant INDEX_NOT_FOUND if the index is not found".
> To me that really obfuscates the meaning.
> 
> Stephen
> 
> ----- Original Message -----
> From: "Gary Gregory" <ggregory@seagullsoftware.com>
> Note that one always free to ignore constants and use magic numbers in
> their code, no matter what the library does internally.
> 
> > Please note that my view pertains only to basic values, like -1 and
> "".
> > When
> > the value refers to something more abstract, like an enumerated
> constant
> > then a constant makes the code much better and more maintainable. I
> just
> > have a place where I draw the line.
> 
> A -1 "index" IS abstract!
> 
> -1 represents an idea, not an index. This is a classic case where an
API
> can return an integer value [0..Integer.MAX_VALUE] which represents
one
> concept: an index; and under other circumstances, the API returns
still
> an integer, but this time representing a completely different idea:
> there is no index.
> 
> Isn't this a perfect example of a "magic number"?
> 
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-dev-help@jakarta.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message