commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From <>
Subject RE: [lang] StringUtils isEmpty summary(2)
Date Sun, 20 Jul 2003 01:55:30 GMT
> d) The isXxxOrNull() naming is disliked as too long even 
> though its clear.

I don't agree with this.  I'm very much in favor of precise,
"intention-revealing" names.  IMHO, isEmpty is unambiguous and should
only mean that there's no content in the referenced String (that is,
string.length() == 0).  Empty means that there's some container that
_could_ hold something, but null means that there's no container there
at all (in a sense, string.length() == N/A).  So, isEmptyOrNull() seems
very straightforward and would remove all doubt that it's checking for

> e) Similarly isEmptyTrimmed() naming is too long.

I don't mind the length, but then I'm not sure here if it's checking for

> f) More people want isEmpty() to be true for null than false.

I can't disagree with that.  While I for sure don't want isEmpty() to
return true for a null (it's not empty, there's no 'it' there to
check!), I'm not sure I like isEmpty() returning false for a null
either, so a NPE would be appropriate.

I would say that my most common usage is a replacement for:

if ( ( string == null ) || ( string.length() == 0 ) )

So I'd be using isEmptyOrNull( string ).

However, there certainly are times that I don't want a null to silently
return false (such as when there's a contract with the rest of the code
that nulls should not exist for this variable) and I'd use isEmpty(
string ) in that case, fully expecting that if string == null, then a
NPE would be thrown and I'd have the underlying bug fixed.


To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message