[Kde-perl] Overloading of operators '==' and '!='

Ashley Winters jahqueel at yahoo.com
Sat May 22 22:25:46 CEST 2004


--- Johannes Plass <johannes.plass at web.de> wrote:
> Deactivation of the overloading can be achieved by commenting
> out the two lines
>      "==" => "Qt::base::_overload::op_equal",
>      "!=" => "Qt::base::_overload::op_not_equal",
> in Qt.pm (at least it works without side effects I'm
> aware of).
> Perhaps it is possible to include that in the next version
> of PerlQt ?

I wonder how painful the transition to correctness would be. You are
quite right that using == and != for content comparisons doesn't match
Perl's operator meanings.

>From a design perspective, any class with the serialization
QDataStream& operator <<() functions should have string comparison
operators which "apparently" act upon their serialized representations.
Therefore, content comparison should have been implemented with C<eq>
and C<ne>, and referential comparison should have been left with Perl's
default C<==> and C<!=>. In fact, there might even be some use to
creating a default implementation of C<cmp> which attempts to serialize
both sides of the operator and perform a string comparison on them, in
the absence of specific comparison operators from Qt.

I would stop short of actually overloading the '""' stringification
operator, simply because I see no point to it. However, how about
replacing the C++ evilness of << for serialization with C<.>?

$x = $point1 . $point2 . $point3;   # $x is QDataStream, now

The inverse operation should be implemented by hijacking the
constructor for serializable objects:

$point1 = Qt::Point($x);
$point2 = Qt::Point($x);
$point3 = Qt::Point($x);

Or, if we want it even more explicit:

$point1 = Qt::Point <$x>;
$point2 = Qt::Point <$x>;
$point3 = Qt::Point <$x>;

Thereby making the destructive/iterative nature of the operation clear
to Perl-Folk. However, given the syntactic limitations of perl's <>
operator (only a simple $scalar variable allowed), both should be
permissable.

/end design brainstorm

Ashley Winters


	
		
__________________________________
Do you Yahoo!?
Yahoo! Domains – Claim yours for only $14.70/year
http://smallbusiness.promotions.yahoo.com/offer 


More information about the Kde-perl mailing list