harmony-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Geir Magnusson Jr <g...@pobox.com>
Subject Re: [classlib] compatibility of toString
Date Tue, 04 Jul 2006 12:04:42 GMT


Richard Liang wrote:
> 
> 
> Geir Magnusson Jr wrote:
>> Tim Ellison wrote:
>>  
>>>>       
>>> Yep, if the spec tells you what the format of the string should be then
>>> follow it (since apps may be dependent upon it), otherwise I'd be
>>> inclined to invent your own useful string representation.
>>>
>>>     
>>
>> This idea scares me.  I think people do depend on toString() when
>> writing apps, and tend to shove that kind of thing to log files and such
>> on server apps.  To have our outptut different from Sun's, BEA's, IBM's,
>> Apple's seens like we're asking for trouble.
>>
>>   
> Hello Geir,
> 
> IMHO, as long as the method does not give confusing message to
> developers, we are not required to have the same behavior. You may want
> to refer to the spec of java.lang.Object.toString:
> ...
> In general, the toString method returns a string that "textually
> represents" this object. The result should be a concise but informative
> representation that is easy for **a person to read**.
> ...

Sure, but that doesn't mean that it would be reasonable to randomly
change the output of a given Class's toString() as long as it would be
easy for a person to read :)

I know that's not what you are advocating, and I certainly agree that no
one should depend on toString() output like that, but I also know that
in production systems *I* have done it, and I'm sure others have as well.

> 
> And there are some cases that we even cannot follow RI.
> e.g.,
> URLConnection conn = new URL("http://www.apache.org").openConnection();
> System.out.println(conn.toString());
> 
> The code above will print
> "sun.net.www.protocol.http.HttpURLConnection:http://www.apache.org"
> 
> Any comments? Thanks a lot.

Well, we could actually print that if that was our impl of URLConnection
for HTTP, but still, I think

"org.apache.harmony.whatever.HttpURLConnection:http://www.apache.org"

would be more reasonable than

"Implementing Class : org.apache.harmony.whatever.HttpURLConnection,
Target URI : http://www.apache.org"

or something like that, even thought the second is perfectly good.

All I'm saying is that unless the output from the RI's toString() is
particularly brain-dead, it doesn't seem to be too much of a bother to
be similar.

Just my $0.02

geir

> 
> Best regards,
> Richard
>> geir
>>
>>
>>
>>
>> ---------------------------------------------------------------------
>> Terms of use : http://incubator.apache.org/harmony/mailing.html
>> To unsubscribe, e-mail: harmony-dev-unsubscribe@incubator.apache.org
>> For additional commands, e-mail: harmony-dev-help@incubator.apache.org
>>
>>
>>   
> 

---------------------------------------------------------------------
Terms of use : http://incubator.apache.org/harmony/mailing.html
To unsubscribe, e-mail: harmony-dev-unsubscribe@incubator.apache.org
For additional commands, e-mail: harmony-dev-help@incubator.apache.org


Mime
View raw message