Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:109413 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 66716 invoked from network); 29 Mar 2020 16:34:50 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 29 Mar 2020 16:34:50 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id BB3671804E6 for ; Sun, 29 Mar 2020 08:00:31 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-0.6 required=5.0 tests=BAYES_00,BODY_8BITS, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS15169 209.85.128.0/17 X-Spam-Virus: No X-Envelope-From: Received: from mail-wr1-f46.google.com (mail-wr1-f46.google.com [209.85.221.46]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Sun, 29 Mar 2020 08:00:31 -0700 (PDT) Received: by mail-wr1-f46.google.com with SMTP id d5so17906750wrn.2 for ; Sun, 29 Mar 2020 08:00:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-transfer-encoding:content-language; bh=d9JsyBYA1gehLEXUzQ+iMy/kDuHZdhpdy10lFtJa7PM=; b=Vw1z0tNCRKWU0fx0nUZs3tzM+0TnYadan/mNpE+Ny5RPf/VmTLwAu1FcZozE9ZdJy6 jxv9/U1kHw2tM+3yJQ70xSqrTz2vqAOWLtbdrlFfY9NewP9m2lPAqrsnd/V2ip33LLkC vDLlM0AAqAggdLtEptTTDDzA0RJj7O6fcQ7lgVFLcfiOk7TrRVIQHNYXuTYI/f6DVIVw 24NIZWUDBCjPd4n+i6JzHsBXeJZpKc/AUpZDAgFNV9jKYBCv13kIVxAXgItLZaro8GFO iidkWJ7MyGX3ZmpmaF/vwXPTvJpq9Ek14i2X0Jqd5xJPTH2ma1C5Tl4Xa9cXd5CJTFjP ea6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=d9JsyBYA1gehLEXUzQ+iMy/kDuHZdhpdy10lFtJa7PM=; b=aq8lEzPtSwhEyN2Qxs5nnmzd8JXAZ6biQOnc5rvJE0lNZc0Loy8wIcuUxFrMkh7e+F Pj73d+XI5jh6gHF3TygI0rva50VgyfvTmc/9VkV9Zs/izeBOP0AukExJ4mNMHpdSb25N GOtmfZCsbDYPu4PbtYTd1c7Jmg8/6khyK78XotWFNHkul6NN4qdXpiWAVrhjvbR9DvRp 5ZjLsb2vX39WSoh+nyI1pUPK8X65nFA0Nj8yyYMMMYuU5QtRaGAgYg896lEOGInvOHpT 49ucnc15/xhK+qsUeD8kE8PItSzoYet9XDJpgTRVAUgt5C0FNn6ij6OewiMzu/4nxckm enYw== X-Gm-Message-State: ANhLgQ2uuO7j9BuADwy39JEcGvvXYEtRMaBoupUE4xB6gS+F7pYQPmVH D4D5120XnePxwgDPvHqbrSra+pea X-Google-Smtp-Source: ADFU+vspjPe/9l8bZXfEXIolNy8GUKlDEcA2v6823kb/fWCFlSpR39QTU4NtC9E76JPWL8XBECfFGw== X-Received: by 2002:a05:6000:105:: with SMTP id o5mr10139324wrx.395.1585494027522; Sun, 29 Mar 2020 08:00:27 -0700 (PDT) Received: from [192.168.0.14] (cpc84253-brig22-2-0-cust114.3-3.cable.virginm.net. [81.108.141.115]) by smtp.googlemail.com with ESMTPSA id i2sm17501316wrx.22.2020.03.29.08.00.26 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 29 Mar 2020 08:00:26 -0700 (PDT) To: internals@lists.php.net References: Message-ID: Date: Sun, 29 Mar 2020 16:00:25 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.6.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-GB Subject: Re: [PHP-DEV] [RFC] [DISCUSSION] Compact Object Property Assignment From: rowan.collins@gmail.com (Rowan Tommins) On 28/03/2020 21:37, Jakob Givoni wrote: > I really believe that COPA can help thousands of PHP developers > without introducing any new complexities to the language and my hope > is that perfect won't be the enemy of good this time around :-) > > Any last words unsaid before the final lap commences? Hi Jakob, It occurred to me thinking about alternative syntaxes that COPA could be seen as a limited form of the "with" statement found in some languages, e.g. JS [1], VisualBasic [2], Delphi [3], Groovy [4] (note that with blocks in Python are something different). [1] https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/with [2] https://docs.microsoft.com/en-us/dotnet/visual-basic/language-reference/statements/with-end-with-statement [3] http://www.delphibasics.co.uk/RTL.asp?Name=With [4] https://docs.groovy-lang.org/latest/html/groovy-jdk/java/lang/Object.html#with(boolean,%20groovy.lang.Closure) The Groovy version is particularly relevant, since it can be used as an expression, not just a statement block, so this example from your RFC: doTheFoo((new Foo)->[     a = 1,     b = 2,     c = 3, ]); would I think look something like this in Groovy: doTheFoo(new Foo().with(true) {     a = 1     b = 2     c = 3 }) The notable differences between COPA and with blocks are: - with statements generally allow methods as well as properties to be referenced on the given object - with blocks contain a series of full statements in some form (either a syntactical block, or some form of closure); COPA instead contains a special list of key-value pairs - with blocks generally fall back to other scopes if a property or method is not found, and are often criticised for the resulting ambiguity COPA trades the scope ambiguity for reduced flexibility: the left-hand side of each assignment is always a property name, and the right-hand-side is a normal expression, so doesn't benefit from the syntax. This example from the RFC: $myObj->[     foo = 10,     bar = $myObj->foo + 20, ]; Wouldn't need the extra reference to $myObj in Groovy: myObj.with {     foo = 10     bar = foo + 20 } Similarly, the nesting example in Future Scope: $foo->[     a = 1,     b = $foo->b->[         c = 2,     ], ]; Could be written something like this: foo.with {     a = 1     b = b.tap {         c = 2     } } If we used a different sigil instead of $ for "property and method of with'd object", we could avoid the ambiguity of most with blocks, but get most of the power; something like this: $foo = new Foo with {     ->a = 1;     ->b = ->1 + 10;      ->c = new Bar with {            ->d = 'Hello';      };     ->start(); } I'm not sure whether I like this idea or not, but I thought I'd share it, because I think COPA as currently proposed is too narrow a use case to deserve a special syntax. Regards, -- Rowan Tommins (né Collins) [IMSoP]