Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:90326 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 39808 invoked from network); 7 Jan 2016 21:22:52 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 7 Jan 2016 21:22:52 -0000 Authentication-Results: pb1.pair.com smtp.mail=nikita.ppv@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=nikita.ppv@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.160.172 as permitted sender) X-PHP-List-Original-Sender: nikita.ppv@gmail.com X-Host-Fingerprint: 209.85.160.172 mail-yk0-f172.google.com Received: from [209.85.160.172] ([209.85.160.172:34986] helo=mail-yk0-f172.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 27/48-21405-B27DE865 for ; Thu, 07 Jan 2016 16:22:51 -0500 Received: by mail-yk0-f172.google.com with SMTP id x67so343707203ykd.2 for ; Thu, 07 Jan 2016 13:22:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=vOA04rTxpApQPLsmpSYzDfQG9/MtVhtPLAJepVOaJJU=; b=Q0HvKX4tXXIYp8s79J0TUPmAIa6fZK51J6XDi1TBcSWfnEcSh0Rjr8EG749Das5G3i iM1KFlJ062wZsDE9o+INu9HHwcSDtg9tSqzIsMGAt6epeqc62WampTLjbq3dSLNPxOot fdUYL/iSw6QvhgTQGa0quWmZEwF9Pe6aXbSu/3IGKAfQDPRMKYRTGn45xfSd6psOZXqK DoP6GjPmDowxpiG4fipsOVp8jcQxwj+FgScEXSkzr4X4nz0Rtg79abPW2rJe8a7Nw7Aj i4QTmIodFPl5b+9e6CQ22gMT7ZCM0q3HGt+/or/yNQCTBYAPpf42zyqmJzeJ6h4qmuXs 4xGQ== MIME-Version: 1.0 X-Received: by 10.129.50.199 with SMTP id y190mr86863888ywy.147.1452201768633; Thu, 07 Jan 2016 13:22:48 -0800 (PST) Received: by 10.129.148.70 with HTTP; Thu, 7 Jan 2016 13:22:48 -0800 (PST) In-Reply-To: References: Date: Thu, 7 Jan 2016 22:22:48 +0100 Message-ID: To: Sara Golemon Cc: PHP internals Content-Type: multipart/alternative; boundary=001a1140847e8fccdc0528c512d7 Subject: Re: [PHP-DEV] [RFC] Differentiate op from assign-op in operator overloading From: nikita.ppv@gmail.com (Nikita Popov) --001a1140847e8fccdc0528c512d7 Content-Type: text/plain; charset=UTF-8 On Thu, Jan 7, 2016 at 8:18 PM, Sara Golemon wrote: > On Thu, Jan 7, 2016 at 5:16 AM, Nikita Popov wrote: > > GMP objects are, with the exceptions of gmp_setbit and gmp_clrbit, > immutable > > value objects. And yes, that's exactly what I would expect any object > > representing a number to be. If $g->add(123) would modify $g instead of > > returning a new object, that would be a major WTF moment for me (and for > > that matter, make the usage very inconvenient.) > > > Sure, but if I called $g->assignAdd(123); then I would expect $g to be > modified. > That's the analogue to += so I while I don't disagree with your > conclusion about add(), I do disagree with your analogy. > I picked the $g->add(123) example from your mail, maybe that was only a typo? To be clear, I don't really have a problem with something like $g->assignAdd(123) *as a performance optimization*. GMP is potentially critical code and depending on the application, the overhead of object and mpz allocations may be significantly higher than the cost of the operations themselves. My point here is only that I don't think these kind of mutable APIs on numbers are a good choice for being part of the primary, go-to API (which for GMP now are the overloaded operators). > > I don't get why you denounce immutable value objects as being "non-object > > objects". Seems like very standard usage to me, and one that seems to be > > increasingly preferred. > > > It's not their immutability which makes me call them that. It's the > lack of anything you would normally see on an object: > * No methods > * No properties > * No constants > * Not initialized via `new` > > GMP objects are just resources by another name, and operator > overloading got built around that model, rather than the model enjoyed > by normal objects. That's why I denounce them as non-object objects. > Thanks, that makes more sense. > >> Leaving GMP out of the equation for now (and I think we need to have a > >> longer discussion about this, but in another thread), I think the > >> question which remains is: Do we want more non-object objects? > >> Should, for example, SimpleXMLbe constrained by GMP's goals when > >> implementing overloaded operators (no, I don't know what this would > >> look like, it's just a for-instance). > > > > > > If we leave GMP out of the equation, then yes, I agree. Whether $a op= $b > > should create a new object or modify an existing one depends on the > nature > > of that object. For GMP (and Rational and Complex and Currency and most > > other things that tend to be immutable value objects) I think the > behavior > > we currently provide is preferable (though I guess that is subject to > > discussion), but for some other applications of operator overloading, > this > > choice wouldn't really make sense. > > > Agreed. The choice of mutability needs to be class specific, which is > why I propose letting the class enforce it rather than dictating it > from the engine and not giving the classes a choice. > > > It's currently already possible to distinguish this based on whether > result > > == op1. However we reserve the right (i.e. have some currently > non-default > > optimizations doing that) to have result == op1 in $a = $a + $b > operations > > as well, so this check is not robust. So, it would be good to change > things > > to pass in separate ZEND_ASSIGN_* flags. Will make the implementation > even > > more ugly though :) > > > Right, that optimization pass is slightly more complex. I haven't had > the bandwidth to dig into it, but assuming a clean/efficient solution > is available, would you be okay with the rest of the proposal overall? > (Non-binding) > Yeah, I totally agree with part 1+2 of the proposal :) Nikita --001a1140847e8fccdc0528c512d7--