On 12/13/02 5:09 AM, Luke Palmer wrote:
>> From: John Siracusa <[EMAIL PROTECTED]>
>> On 12/12/02 4:01 PM, Larry Wall wrote:
>>> On Thu, Dec 12, 2002 at 12:40:52PM -0600, Garrett Goebel wrote:
>>> : So we'll _have_ to write $obj.*id when we mean $obj->UNIVERSAL::id;
>>> 
>>> If you wish to be precise, yes.  But $a.id eq $b.id should work for most any
>>> class that uses the the term "id" in the typical fashion.
>> 
>> I still feel like we're talking past each other here.  What I was saying is
>> that, regardless of any admonitions to the contrary, I think people will
>> still write this:
>> 
>>     $a.id == $b.id
>> 
>> and expect it to compare memory addresses.
> 
> And presumably, anyone who overrides .id in their own class knows what
> they're doing.  They, in fact, I<want> statements like that to behave
> that way.

I think you're missing my point.  I'm saying that there are many kinds of
objects that naturally want to have an "id" method or attribute that has
nothing whatsoever to do with "this is the same object" comparisons.  But if
"id" is chosen as the name of the global "this is the same object" method in
Perl 6, then no one can safely use a method named "id" (overridden or
otherwise) for anything but "this is the same object" comparisons.

I think this is a bad idea because "this is the same object" comparisons are
relatively rare, and do not deserve to be hogging the short, direct method
name of "id".

Example: Instead of getting a user id via $user.id and a product id via
$product.id, Perl 6 programmers will be forced to mark-up their methods
names ($user.uid, $product.pid) and then deal with the differences in any
heterogeneous collection:

    # Too bad the method named "id" is taken by a value that
    # you're rarely interested in, huh :P
    for @users, @products, @transactions, @mixed -> $thing
    {
      print $thing.type, " id ";

      given  $thing.type
      {
        when 'user'        { print $thing.uid }
        when 'process'     { print $thing.pid }
        when 'transaction' { print $thing.tid }
        ...
      }

      print "\n";
    }

As opposed to:

    # Ah,  blessed sanity...
    for @users, @products, @transactions, @mixed -> $thing
    {
      print $thing.type, " id ",  $thing.id, "\n";
    }

(Yes, you could just decide that all your objects will use "oid" or
something else, but that would be another symptom of the problem: Perl 6 is
forcing you to (slightly) obfuscate your code.  Your first thought was to
simply use the well understood name "id" like you always have, but you're
out of luck.)

Using the method/attribute named "id" for "this is the same object"
comparisons is just plain bad Huffman coding.  The "this is the same object"
method/attribute should have a name that reflects the relative rarity of its
use.

-John

Reply via email to