You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Gary Gregory <gg...@seagullsw.com> on 2004/03/11 01:41:55 UTC

[lang] CharUtils.isAscii methods and CharSet, two issues

Hello,

Looking at the new CharUtils class and its isAscii methods and the
CharSet class, something feels slightly off.

(1)
The first thing is that the isAscii* could be implemented in terms of
already existing CharSet code. 

For example, in CharUtils:

    public static boolean isAsciiAlphaUpper(char ch) {
        return (ch >= 'A' && ch <= 'Z');
    }

Eating our own dog food:

    public static boolean isAsciiAlphaUpper(char ch) {
        return CharSet.ASCII_ALPHA_UPPER.contains(ch);
    }

(2)
The second item that I am wondering about is the introduction of methods
like is{Encoding}SomeCondition(char). This is believe is not OO. One
should ask the question to some encoding object, which is what CharSet
looks to be for.

Would it make sense to improve CharSet with these condition methods such
that one could write:

CharSet.ASCII.isAlphaUpper(ch)
CharSet.ASCII.isWhatever(ch)

?

Thank you,
Gary


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


Re: [lang] CharUtils.isAscii methods and CharSet, two issues

Posted by "matthew.hawthorne" <ma...@apache.org>.
Todd V. Jonker wrote:
> As is stands, isAsciiAlphaUpper follows
> DoTheSimplestThingThatCouldPossiblyWork but (perhaps) breaks
> OnceAndOnlyOnce.
> 
> Still, I think the existing code is better.  Such things tend to be
> called inside tight inner loops, and as such every bytecode counts.  Your
> suggested rewrite adds no functional improvement while increasing the
> execution time manyfold.  I strongly suggest leaving it as-is.


I think that running some performance tests would provide the best 
insight into possible effects on execution time.  Gary, maybe you could 
write a small test to see if this change truly would cause a performance 
problem?

There are lots of good changes that don't add any functional improvement 
at the machine level, but a more OO solution may very well improve 
things at the maintenance and class heirarchy level.


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


Re: [lang] CharUtils.isAscii methods and CharSet, two issues

Posted by "Todd V. Jonker" <to...@consciouscode.com>.
As is stands, isAsciiAlphaUpper follows
DoTheSimplestThingThatCouldPossiblyWork but (perhaps) breaks
OnceAndOnlyOnce.

Still, I think the existing code is better.  Such things tend to be
called inside tight inner loops, and as such every bytecode counts.  Your
suggested rewrite adds no functional improvement while increasing the
execution time manyfold.  I strongly suggest leaving it as-is.


On Wed, 10 Mar 2004 19:41:55 -0500, "Gary Gregory"
<gg...@seagullsw.com> said:
> Hello,
> 
> Looking at the new CharUtils class and its isAscii methods and the
> CharSet class, something feels slightly off.
> 
> (1)
> The first thing is that the isAscii* could be implemented in terms of
> already existing CharSet code. 
> 
> For example, in CharUtils:
> 
>     public static boolean isAsciiAlphaUpper(char ch) {
>         return (ch >= 'A' && ch <= 'Z');
>     }
> 
> Eating our own dog food:
> 
>     public static boolean isAsciiAlphaUpper(char ch) {
>         return CharSet.ASCII_ALPHA_UPPER.contains(ch);
>     }

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