develooper Front page | perl.perl5.porters | Postings from July 2010

Re: Order of evaluation of terms (was peephole optimiser could prune more dead code)

Thread Previous | Thread Next
From:
Joshua ben Jore
Date:
July 15, 2010 16:23
Subject:
Re: Order of evaluation of terms (was peephole optimiser could prune more dead code)
Message ID:
AANLkTikbAIsrjvgyvosyju7m3uZJR5GkgJ_VKw6iP1qR@mail.gmail.com
On Thu, Jul 15, 2010 at 1:50 PM, Jan Dubois <jand@activestate.com> wrote:
> Once you implement magic/overloads that violate the underlying algebraic
> relationships in your overloaded operators you will end up in a world
> of pain.  E.g. the following expressions should always be true:
>
>    ($a + $b) == ($b + $a)
>    ($a < $b) == ($b <= $a)
>    "$a" eq $a
>    ($a eq $b) && ($b eq $c) == ($a eq $c)

FWIW, while I'm otherwise in agreement, I wouldn't want to impute
parameter reordering to operators like + because of their common
overloading to mean string concatenation.

    "X" + "Y" == "Y" + "X"

This isn't reasonably true if these strings are some kind of object
that does concatenation and == is maybe something other than numeric
equality.

Josh

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