cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Antonio Gallardo" <agalla...@agssa.net>
Subject Re: cvs commit: cocoon-2.1/src/blocks/scratchpad/java/org/apache/cocoon/ant AntBuildGenerator.java CocoonTask.java
Date Sat, 17 Apr 2004 13:31:13 GMT
Ugo Cei dijo:
>>   Modified:    src/blocks/scratchpad/java/org/apache/cocoon/ant
>>                         AntBuildGenerator.java CocoonTask.java
>>   Log:
>>   Using commons.lang
>
>>   -    private static final String EMPTY_STRING = "";
>>
>>   -        MSSG_ATTRS.addAttribute(EMPTY_STRING, PRIORITY, PRIORITY,
>> CDATA, null);
>>   -        NAME_ATTRS.addAttribute(EMPTY_STRING, NAME, NAME, CDATA,
>> null);
>>   +        MSSG_ATTRS.addAttribute(StringUtils.EMPTY, PRIORITY,
>> PRIORITY, CDATA, null);
>>   +        NAME_ATTRS.addAttribute(StringUtils.EMPTY, NAME, NAME,
>> CDATA, null);
>
> I hereby propose to patch commons-lang to include a couple more utility
> values like:
>
> public class ObjectUtils {
>    public static final Object NULL_OBJECT = null;
> }

Exists something similar but not this Object:
http://jakarta.apache.org/commons/lang/api/org/apache/commons/lang/ObjectUtils.html#NULL
>
> public class NUMBER_UTILS {
>    public static final int ZERO = 0;
>    public static final int ONE = 1;
> }

I think this is not good. It was useful some time ago to define a Boolean,
but in Java it has no meaning. We have Boolean for that.

> public class BooleanUtils {
>    public static final boolean TRUE = true;
>    public static final boolean FALSE = false;
> }

Already we have Boolean.TRUE and Boolean.FALSE in standard java.lang lib:
http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Boolean.html#TRUE

> assuming they're not already there.

See answer above.
>
> It should be obvious to anyone that the usefulness of this is to ensure
> that, should, one day, the meaning of "empty string", "null value",
> "true" or "zero" change, we can apply the change it in one place. God
> have mercy of those poor souls who will have to hunt through thousands
> of source files for every occurrence of "" and change it. Fools!

I think it is a good programming practice plus:

It saves resources. I think some people then to abuse the Garbage
collector with no reason. Did you really think it is better to make a:

Boolean b = new Boolean(true) instead of

Boolean b = Boolean.TRUE

Both expresion got the same result, but the first innecesary create
another Object on the memory. That later the garbage collector need to
free. This is my POV. The same happen with

StringUtils.EMPTY vs. ""

Users often rant about Cocoon slowness and maybe in part because of abuse
of garbage collector.

> And with the aim of reaching 100% test coverage, our job wouldn't be
> complete without a comprehensive test suite:
>
> public void testNullIsNull() {
>    assertIsNull("NULL_OBJECT is not null", ObjectUtils.NULL_OBJECT);
> }
>
> public void testZeroIsNotOne() {
>    assertNotEquals("Zero is one", NumberUtils.ZERO, NumberUtils.ONE);
> }
>

Cruel sarcasm...

> and so on...

Ask people on jakarta commons why they write this kind of stupid code or
need we to reinvent the wheel over and over to show how smart programmers
we are?

I really believe in the code reutilization. Jakarta commons lang is part
of the core of Cocoon. Why we need to wrote the same code over and over?

In jakarta commons there is also another interesting libs that we can make
use of them:

http://jakarta.apache.org/commons/io/
http://jakarta.apache.org/commons/codec/
http://jakarta.apache.org/commons/collections/
http://jakarta.apache.org/commons/validator/
http://jakarta.apache.org/commons/betwixt/
http://jakarta.apache.org/commons/fileupload/


Best Regards,

Antonio Gallardo

Mime
View raw message