You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cocoon.apache.org by Ugo Cei <ug...@apache.org> on 2004/04/17 14:33:06 UTC

Re: cvs commit: cocoon-2.1/src/blocks/scratchpad/java/org/apache/cocoon/ant AntBuildGenerator.java CocoonTask.java

>   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;
}

public class NUMBER_UTILS {
   public static final int ZERO = 0;
   public static final int ONE = 1;
}

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

assuming they're not already there.

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!

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);
}

and so on...

	Ugo


Re: cvs commit: cocoon-2.1/src/blocks/scratchpad/java/org/apache/cocoon/ant AntBuildGenerator.java CocoonTask.java

Posted by Joerg Heinicke <jo...@gmx.de>.
On 17.04.2004 15:31, Antonio Gallardo wrote:

> 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?

But with a change like

>   -        File workDirParent = new File(System.getProperty("java.io.tmpdir", "."));
>   +        File workDirParent = new File(SystemUtils.JAVA_IO_TMPDIR != null ? SystemUtils.JAVA_IO_TMPDIR : ".");

you seem to counteract this goal.
System.getProperty(String key, String default) has probably the same 
logic that you implemented above on your own.

Joerg

Re: cvs commit: cocoon-2.1/src/blocks/scratchpad/java/org/apache/cocoon/ant AntBuildGenerator.java CocoonTask.java

Posted by Antonio Gallardo <ag...@agssa.net>.
Ugo Cei dijo:
> Il giorno 17/apr/04, alle 15:31, Antonio Gallardo ha scritto:
>
>> I think it is a good programming practice plus:
>>
>> It saves resources.
>
> No, it does not.
>
> ``String literals-or, more generally, strings that are the values of
> constant expressions (§15.28)-are "interned" so as to share unique
> instances, using the method String.intern.''
>
> (http://java.sun.com/docs/books/jls/second_edition/html/
> lexical.doc.html#101083)
>
> This means, unless I'm seriously mistaken, that you can always use ""
> instead of StringUtils.EMPTY without using a single bit of memory more.
> And there's no GC involved.

Thanks for pointing out the error. You are right. I will rewrote it as it
maybe. The change was really meaningless and the original code too.

Best Regards,

Antonio Gallardo.

Re: cvs commit: cocoon-2.1/src/blocks/scratchpad/java/org/apache/cocoon/ant AntBuildGenerator.java CocoonTask.java

Posted by Ugo Cei <ug...@apache.org>.
Il giorno 17/apr/04, alle 15:31, Antonio Gallardo ha scritto:

> I think it is a good programming practice plus:
>
> It saves resources.

No, it does not.

``String literals-or, more generally, strings that are the values of  
constant expressions (§15.28)-are "interned" so as to share unique  
instances, using the method String.intern.''

(http://java.sun.com/docs/books/jls/second_edition/html/ 
lexical.doc.html#101083)

This means, unless I'm seriously mistaken, that you can always use ""  
instead of StringUtils.EMPTY without using a single bit of memory more.  
And there's no GC involved.

It's just obfuscation without any efficiecy gain.

> Did you really think it is better to make a:
>
> Boolean b = new Boolean(true) instead of
>
> Boolean b = Boolean.TRUE

Never said that.

> 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. ""

I'm afraid you are wrong about this, dear friend.

> 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?

There is NO code to write or reuse in this case. A simple "" is enough.

	Ugo


Re: cvs commit: cocoon-2.1/src/blocks/scratchpad/java/org/apache/cocoon/ant AntBuildGenerator.java CocoonTask.java

Posted by Antonio Gallardo <ag...@agssa.net>.
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