Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:123546 X-Original-To: internals@lists.php.net Delivered-To: internals@lists.php.net Received: from php-smtp4.php.net (php-smtp4.php.net [45.112.84.5]) by qa.php.net (Postfix) with ESMTPS id 9C5F91A009F for ; Fri, 7 Jun 2024 19:20:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1717788076; bh=RAO4Yyoaq13YHLT9jIC1LRdIaiE13DeHxk2StEIMyPk=; h=Date:Subject:To:References:From:In-Reply-To:From; b=XIvo6AhOBogrWgAgeeA4L/NX+v/xcJUc9039noVaDTdeIkAfbHsaNagTp0hVkSyUi DpgBAJOx2oDJceXvrZAB4HIXRh7Jla3wj2PPXUuKN1XDy3Kj0IA+11GyQ2Evp5beDj ptDeJZ2mH7GJrO42d/68ayuVglqSeO/O9kCHkyOifnC9/oCigZmb17OLNsW48ZkelF +ZbQKELou2bMrSiC2t9dO7WX7NNRupxt0uSzbmEAwTAzR7dlnknDEz2dPbs1tkABv4 qDchvOuTRNPYR1gEzkSL56aJ5svaQRjelLPnRLitxjtRseoeo3H9f5d7MjYms6HakN xvPaVEDBbRAaA== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 096EA180341 for ; Fri, 7 Jun 2024 19:21:13 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-0.1 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_MISSING,HTML_MESSAGE, RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: Error (Cannot connect to unix socket '/var/run/clamav/clamd.ctl': connect: Connection refused) X-Envelope-From: Received: from smtp-bc0e.mail.infomaniak.ch (smtp-bc0e.mail.infomaniak.ch [45.157.188.14]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Fri, 7 Jun 2024 19:21:08 +0000 (UTC) Received: from smtp-4-0001.mail.infomaniak.ch (smtp-4-0001.mail.infomaniak.ch [10.7.10.108]) by smtp-3-3000.mail.infomaniak.ch (Postfix) with ESMTPS id 4Vwrcd6SBKzL7H for ; Fri, 7 Jun 2024 21:20:01 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=processus.org; s=20231208; t=1717788001; bh=1rjizCHTkL0sFSMPt4GTyFxg5bhOLMjQ60wOhzyKCQs=; h=Date:Subject:To:References:From:In-Reply-To:From; b=jeCWLGIq8jgPS5eopDk4qqJgu7B3/Mv03rYD6nvNbYg3vOTIXIIIFw+YaVhnYqa+9 cX6YY5GNnJUgy/8YDr0pK7TBxind24+Fu9+zJjZBs1ZyPkK37hovv0taTC8EY0TYTU bWwVadiU+7U5R7LocrexAM2hHH9v+YaSkoZu9ZGSYSqwY+FXKM0B7XxzM5KNJXV8TZ eGt45qOyoYINYgnf3J+YqmrpNt09yZX34ou3EgvvBAckCDRygsxi/EEFOPrBXFft1T Q8P53Sgdz8mE+xSePB/UvMRyAdxGHnVQRUEgzbh9mrrqvfGhHXfqEDPgXEoAezbuUx l/bwNFlKXnF+Q== Received: from unknown by smtp-4-0001.mail.infomaniak.ch (Postfix) with ESMTPA id 4Vwrcd3g8KzKkg for ; Fri, 7 Jun 2024 21:20:01 +0200 (CEST) Content-Type: multipart/alternative; boundary="------------sOoA3j0dfGAIqC8lsRJES2yr" Message-ID: Date: Fri, 7 Jun 2024 21:20:01 +0200 Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PHP-DEV] RFC proposal : "new" keyword shorthand To: internals@lists.php.net References: Content-Language: fr-FR, en-US In-Reply-To: X-Infomaniak-Routing: alpha From: pierre-php@processus.org (Pierre) This is a multi-part message in MIME format. --------------sOoA3j0dfGAIqC8lsRJES2yr Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Le 07/06/2024 à 18:03, Benoît Condaminet a écrit : > Hello, > > Following the RFC process, I'm sending this to propose a PHP change. > More precisely a new zend language token. > > This is somehow linked to the recently accepted RFC called "new > MyClass()->method() without parentheses", the goal is to introduce a > shorthand for the "new" keyword. > > *Motivations :* > The new keyword sometime has a bad DX, for example when chaining Class > instantiation like this : > $foobar = new Foo( new Bar(), new Etc()); > > We can quickly have very long class object construction in some case. > > In lot of Framework, to improve DX, static function construct are > often used to avoid the new keyword, some create additional object > builders, etc. > > As a first try, I start updated code to completely make the new > keyword optional, like in Dart language for example, but it require > very big change, with lot of impact (collision with function). > > So here is *my proposal : * > > Add a "new" shorthand, using the tilde character : "~" > I made a POC, and it works well, declaring a new language > token T_SHORT_NEW that simply reuse ZEND_AST_NEW under the hood. > Hello, I sincerely do not want to see a new operator for replacing the "new" operator, because then we would have two different syntaxes which would be semantically equivalent. Creating a new object, in most API design, is not something you do very often, especially when working in a framework that does it for you (dependency injection, etc...). And, moreover, when I'm searching who what where was created an specific class instance, I regex grep for "new\s+ClassName" and in most case, it works like a charm. If you add an operator for this, it simply will create a huge cognitive dissonance for simply no added value at all. "New" is working fine, adding a shortcut for the sake of adding a shortcut to something you don't write that much doesn't worth it in my opinion: there are much more disadvantages that benefits. Best regards, Pierre --------------sOoA3j0dfGAIqC8lsRJES2yr Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 8bit
Le 07/06/2024 à 18:03, Benoît Condaminet a écrit :
Hello,

Following the RFC process, I'm sending this to propose a PHP change. More precisely a new zend language token. 

This is somehow linked to the recently accepted RFC called "new MyClass()->method() without parentheses", the goal is to introduce a shorthand for the "new" keyword. 

Motivations :
The new keyword sometime has a bad DX, for example when chaining Class instantiation like this :
$foobar = new Foo( new Bar(), new Etc());

We can quickly have very long class object construction in some case. 

In lot of Framework, to improve DX, static function construct are often used to avoid the new keyword, some create additional object builders, etc.

As a first try, I start updated code to completely make the new keyword optional, like in Dart language for example, but it require very big change, with lot of impact (collision with function). 

So here is my proposal : 

Add a "new" shorthand, using the tilde character : "~"
I made a POC, and it works well, declaring a new language token T_SHORT_NEW that simply reuse ZEND_AST_NEW under the hood. 

Hello,

I sincerely do not want to see a new operator for replacing the "new" operator, because then we would have two different syntaxes which would be semantically equivalent.

Creating a new object, in most API design, is not something you do very often, especially when working in a framework that does it for you (dependency injection, etc...).

And, moreover, when I'm searching who what where was created an specific class instance, I regex grep for "new\s+ClassName" and in most case, it works like a charm. If you add an operator for this, it simply will create a huge cognitive dissonance for simply no added value at all.

"New" is working fine, adding a shortcut for the sake of adding a shortcut to something you don't write that much doesn't worth it in my opinion: there are much more disadvantages that benefits.

Best regards,

Pierre

--------------sOoA3j0dfGAIqC8lsRJES2yr--