Re: Overloading of operators '==' and '!='
Ashley Winters <[email protected]>
| Newsgroups | gmane.comp.kde.devel.perl |
|---|---|
| Message-ID | <[email protected]> |
--- Johannes Plass <[email protected]> wrote: > Hi all, > > being a PerlQt noob I would like to send a big > "Thank You for this wonderful software" to the > PerlQt developers, maintainers, supporters and > documentation writers (did I miss someone ?). > This is really a tool that saves me about > 48 hours a day ..... > > Enough praising, here's a tiny recommendation > I would like to throw into the discussion pool: > > In PerlQt the copy constructor ('=') isn't overloaded > since "it clashes with the perl paradigm" (as stated > in the Changelog of 3.006). > Now, for the same reason, I'd like to recommend to > drop the overloading of operators '==' and '!='. > The operators as they act now cause a loss of > the object's identity based on reference comparison. > > Example: > Create a subclass MyPoint of Qt::Point, then construct > lots of MyPoint objects and stuff them in a list. > Now you're in trouble when you want to find > a specific object in this list (for instance in order > to remove it), since code like > if ($list[$i] == $mypoint) ... > doesn't check the identity of the references but the > equalness of the objects x and y coordinates. Well.... perhaps the "correct" (semantically, not logically) way to do this should be documented somewhere? if($list[$i] eq $mypoint) { ... Depending on the ref-stringification is unsightly, but it works. My sincere apologies for the non-DWIM behavior of object comparison. Perl needs an "is" operator or something. :) Ashley Winters __________________________________ Do you Yahoo!? Yahoo! Domains Claim yours for only $14.70/year http://smallbusiness.promotions.yahoo.com/offer