Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:101634 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 51767 invoked from network); 20 Jan 2018 03:29:08 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 20 Jan 2018 03:29:08 -0000 Authentication-Results: pb1.pair.com smtp.mail=aidantwoods@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=aidantwoods@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.215.49 as permitted sender) X-PHP-List-Original-Sender: aidantwoods@gmail.com X-Host-Fingerprint: 209.85.215.49 mail-lf0-f49.google.com Received: from [209.85.215.49] ([209.85.215.49:44284] helo=mail-lf0-f49.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id A9/13-12394-387B26A5 for ; Fri, 19 Jan 2018 22:29:07 -0500 Received: by mail-lf0-f49.google.com with SMTP id w23so4341709lfd.11 for ; Fri, 19 Jan 2018 19:29:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=JLf/J4k+WWH4t7Xy+j3N888wpw8poqxwdoEnQ19mq0U=; b=FpX4Aszkpd9ov5YNM6FIxfLL4lFscsmMhsh12xzM9aztwIqUduKm42YQervFOs8qU7 44LWQzBu+Z0Al8/TbWodggXVlZ5ApkZhfdFyfCfoOdoW5xc26kxBAr5lbJvJGwFjOU0f hEnv0rCwV2brYtdlzrN7C+ICba+kvnB4OMbEQ9XXwAgu++rMCZJ7vSnSQwW2FnXVitRH LadVqZd6I2eEMj20SyHklCtx8Tm+PobEZje+AsRRN2enDXWr5SJYzB8Oxa8r78gto6GL ZrsGJPBHYnXjWMMNfGHToW//TgazOGDi2CCkKVPiDPY90nS2DpUG95ow0FqkStPKVquY pHDw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=JLf/J4k+WWH4t7Xy+j3N888wpw8poqxwdoEnQ19mq0U=; b=pqLFlenzcstvqjrm51n6Le8Wm+sqy7qVz/d8RNUX8SbampBCtv/oR8gDbaJCVKqhky afDB19pHycDscERyEHM9Kthk8qrbe27V9hbW3+Qbw5AD/fXpYdsGD7maqWnRNDZ71gPh p2xTTu+W2u8uHD7fEUOhmOoE+6dlInYR9vtxg93l2VGT4kK/3M70AJg0P7lR7gRAWjrv DADIVfLXO84Hdr+jgQt016uCJasmQmWvxVxYpqy1iTHgWxZHM7QTWvG5uMfbjXsUKS/L +KxQOZ/MbV8ZIC96cHhPrMo14oPKJDoA1wAEQ5bffYT7lHWTIJtCV5sCy1JMHV/R5WaY ilJg== X-Gm-Message-State: AKwxytem6+C/089DgM9ad4EufyPKNb/QZ26l+jbkuj5zB1HCvME8x/c/ rKhzOELdi6qoTapApCnALBatqHv0wdpHJDfhJQU= X-Google-Smtp-Source: AH8x224XIQnxMoeiYGkODeVo15U5CvX1Uh7VGGZLXxsxg1VYrPotvbE6QVyl+Q3KdZSYXFsjSiVSrAldkivz9LTiopE= X-Received: by 10.46.41.71 with SMTP id u68mr271196lje.17.1516418944337; Fri, 19 Jan 2018 19:29:04 -0800 (PST) MIME-Version: 1.0 Received: by 10.46.29.151 with HTTP; Fri, 19 Jan 2018 19:29:03 -0800 (PST) In-Reply-To: References: <9a4e54d1-10d8-889e-e705-fe473e2e3713@gmail.com> <3aa2372c-c31a-d41a-f455-35ce400b382b@gmx.de> Date: Sat, 20 Jan 2018 03:29:03 +0000 Message-ID: To: Andreas Hennings Cc: Sara Golemon , "Christoph M. Becker" , Stanislav Malyshev , PHP internals Content-Type: multipart/alternative; boundary="001a114ff582820b4c05632ccc4e" Subject: Re: [PHP-DEV] null coalesce addition assignment operator ??+= From: aidantwoods@gmail.com (Aidan Woods) --001a114ff582820b4c05632ccc4e Content-Type: text/plain; charset="UTF-8" On 20 January 2018 at 01:25, Andreas Hennings wrote: > On 19 January 2018 at 16:12, Sara Golemon wrote: > > On Thu, Jan 18, 2018 at 7:13 PM, Christoph M. Becker > wrote: > >> On 18.01.2018 at 23:58, Stanislav Malyshev wrote: > >> > >>>> I propose even more such operators: > >>>> null coalesce addition assignment ??+= (for strings and numbers) > >>>> null coalesce subtraction assignment ??-= > >>>> null coalesce increment ??++ > >>>> null coalesce decrement ??-- > >>>> null coalesce multiplication assingment ??*= > >>> > >>> I think this is taking it too far. If you want language like that, you > >>> always have APL :) > >> > >> Why do we discuss extensions to an operator which has still (after > >> nearly two years) not be implemented due to implementation difficulties? > >> > > Am I the only one who looked at the original post and assumed he was > > taking the piss? > > Similar to the jokes about spaceship assignment <=>= and > > equality/identicality assignment === (not to be confused with > > identical non-assign, which is ===) and ====. > > I can definitely say it was not a joke. > I can see myself and others use the ??+= and also ??++, and would have > used them in the past, if they had been available. > The others, I don't care as much. > > For me, a good enough conclusion of this conversation would be one of: > A: Yeah seems useful, but let's wait (or work) until ??= is > implemented and released, and observe how it is being used. > B: No one will ever use it, and it would hurt the language. > > Going by the example, would this operator's behaviour be a little confusing? As I understand it the (maybe) upcoming `??=` operator will assign in the case that the lhs is *not defined*. But for `??+=` incrementing appears to be desired when the lhs *is defined*, (with assignment to the operator related identity element in the case that the lhs is undefined). While the use-case seems to add value in the scenario, I think it is possibly inconsistent with the way `??=` works? Furthermore, I think you can generalise this in user-land and end up with a better result. When dealing with structured data (i.e. when you expect strings mapping to ints in your example) you may consider writing a simple class for making such type guarantees. Something simple like https://3v4l.org/5Sh04 would produce the desired result, and let you obtain the result in one line at point of use. Nothing ties you into using a class for the storage though, you could simplify even further and just create some abstract class representing an "array toolbox" for these kind of operations, e.g. https://3v4l.org/ZJcom So that the array initialisation, foreach loop, and operator are replaced with a single line again at point of use (after defining the arraytools class once). If you wanted it to work more generally, you could use a reference to delay lookup, and keep your current code structure https://3v4l.org/TJYhq If you wanted it to look the part you could even sneak some unicode symbols in to make it look like some sort of operator ;-) https://3v4l.org/MVT85 Kind regards, Aidan --001a114ff582820b4c05632ccc4e--