develooper Front page | perl.perl6.documentation | Postings from December 2002

Re: Stringification of references and objects.

Thread Previous | Thread Next
From:
Joseph F. Ryan
Date:
December 5, 2002 21:21
Subject:
Re: Stringification of references and objects.
Message ID:
3DF033FF.2020002@osu.edu
Brent Dax wrote:

>Joseph F. Ryan:
># By default, references should not stringify to anything 
># "pretty", they should stringifiy to something useful for 
># debugging.  Heck, even perl5 style should be fine.  Not only 
>
>Why?  Isn't the pretty form more generally useful?
>

I don't think so; I'd think it to be annoying to have type more code
in order to specify a more cocise form; if I need to dump a structure,
I'd prefer to do it manually.

># is this handy, but also prevents problems with circular 
># referencing data structures, huge data structures, etc.  
># However, all built-in types should have a .repr() method, 
># which should provide primitive Data::Dumper-ish output
># 
># So:
># 
>#    $var = [1,2,3];
>#     print "$var";
>#     print "\n";
>#     print "$($var.repr)";
># 
># Might print something like:
># 
># [REF_TO_ARRAY_AT: '0x1245AB']
>
>What's wrong with a Perl 5-esque format for the debugging version?
>
>	Array(0x1245AB)
>
>Personally, I like this format.  It's succinct, informative, and tells
>you enough to do identity testing.
>  
>

I like it too, but I thought everyone else hated it :)

># Next, objects:
># 
># Objects should have an AS_STRING method inherited from 
># UNIVERSAL defined as follows:
>
>I'd prefer if we drop the capitals.  str() ought to work fine, IMHO.
>
># method AS_STRING() {
>#     return "[CLASS_INSTANCE_OF: '" ~ $self.CLASS() ~ "']";
># }
>
>Once again, what's wrong with:
>
>	method str() {
>		#Unnamed invocant means you need $_, right?
>		return $_.class() ~ "($_.id())";
>	}
>
>(where id() returns a uniquely identifying integer, usually the
>address).
>

Objects aren't references anymore, are they?  So I don't think it is
apporpriate for an object to stringify with its id.

Joseph F. Ryan
ryan.311@osu.edu


Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About