Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:125378 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 3EE981A00BD for ; Sun, 1 Sep 2024 20:22:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1725222275; bh=PfTet5xYhpCkkrp+A92ckP+IPeOCU773HddzQ6ZJbJM=; h=From:Date:Subject:To:From; b=nmz0AE+5ldm5WWgNujqsRS5QA/VBgv/jnJbvqWLLJMqhNbIFqW0RnxqhHMjgsiN3T cd2wGV3f0PXoFW++6pNkc30dnWjKbjU1j2cejozS8OBUQivdqFGVDAW7uaDtO/Z1Jj /h6JqlsInBH2TdnUIWQCH8wI9TdhrO1uFylGL4AJmWoQne3sR/hnNEZ4WiwItadDad ACUaIe+a6K1e9AGKzjK0bCNHLauWqVweWhTzC2T0l1267ectlQNrozhIK9u1rpyTLG Wuq4NmawgPIZQKsVq9uNx13/fibThquTpkQ3FwX/dfgoszM818C5IHwDGvcAxctsIX zmjWrZHqhqQDg== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 97148180079 for ; Sun, 1 Sep 2024 20:24:34 +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.6 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,FREEMAIL_FROM, HTML_MESSAGE,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL, SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from mail-ot1-f51.google.com (mail-ot1-f51.google.com [209.85.210.51]) (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 ; Sun, 1 Sep 2024 20:24:34 +0000 (UTC) Received: by mail-ot1-f51.google.com with SMTP id 46e09a7af769-709340f1cb1so1032944a34.3 for ; Sun, 01 Sep 2024 13:22:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1725222157; x=1725826957; darn=lists.php.net; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=ED8NK1j3W93k6tFovdRxQJHJUWpQzfWrTElSCOncqE4=; b=kPRZ8Vhs/VasdUYLdzZCt/ZLG/WC4n2GC/n8pKxFJmUlzI79lzmKoCWiC++aRcberc 7Ep42rFzX+cK9JbKtW4EsV1u6VePd9Xdvr0VpaAzL4kULGu+TQ8FJKETRJQf9aMssoq8 xWkDmq9prqEZvIOmigUjzg4wyaq8OvAC5HHpHh6CZHhcEnoJcCvcegyStB6Hl+wIeLry jYM5ni1FLG8fwKLj4zi1rVlRZrgCYjC360k2jlwRlewcN4nVDXtE6PosZO7kIK5hv4XN qEs1CgAWLt7BnTx85S6izznJKE2I5XVcNCetc0qkwAvjRao/J/N4UTvdLbtUwyQRNzOe oYqg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725222157; x=1725826957; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=ED8NK1j3W93k6tFovdRxQJHJUWpQzfWrTElSCOncqE4=; b=JRaxSO2BPXh21fBlCjqvcpzsRz8NXWByu3YPEuNQdOrWuJ4O43E/YWmadD+G+MxPPs hMgg8vsD437Hn+r7e1ynro8n39Kko1HWJz5VV4uZY/+I7BJbrNZMp4l2MZF+Rtbi2F88 SdNtz4zbxd8lXWfya8BF8ccWn3pR7ZhCpgTN0EQu6S5hPgrMj2tJT9CDsy72wYzaN6V/ 1vg0VJF2/ScuJWQDIMujQ6Unpjpw1W8nJ0aOiNTeqytpZXScfrrcf/OTzWi8siceBS+d T3TcjSH42J+mzEIDNs8HZu22NgUvHu+YD7BvkMxlQPQCDfN6gWhE/unmxAl8AgiMe7zw LO0Q== X-Gm-Message-State: AOJu0YxDdffUiN8yZfVWMiixzngGCGWm0H6Y3EJJ7dkcZKLAwNB1FsTJ 97OXz52cc4lDcNXorpSRhmGR7X4Dr72tYLt4YZYEaQgRLXxdxC2U09GDUkk1oeClV36fH4Dkp+W cFTLhmqfsGP3kJ1hYhf55qM9K8BEv66/S X-Google-Smtp-Source: AGHT+IHGS9zFZz5Fc22fMdSyzpgIReyGUZ2tg3gE+GwfEcPqpoqvMFiz0D7oWTpvByVAcdAxjydMBIllOhIG0EK12hs= X-Received: by 2002:a05:6830:2c09:b0:70f:5840:2367 with SMTP id 46e09a7af769-70f7072eb72mr6655200a34.23.1725222156996; Sun, 01 Sep 2024 13:22:36 -0700 (PDT) Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 Date: Sun, 1 Sep 2024 14:22:25 -0600 Message-ID: Subject: Re: [PHP-DEV] RFC: Default Expression To: internals@lists.php.net Content-Type: multipart/alternative; boundary="000000000000d397950621149500" From: hamiegold@gmail.com (Hammed Ajao) --000000000000d397950621149500 Content-Type: text/plain; charset="UTF-8" Hi all, I've been following the discussion on the Default Expression RFC, and while I appreciate the effort to introduce more flexibility in handling default values, I have some significant concerns about this proposal. I'd like to share my thoughts and invite further discussion. 1. Complexity vs. Benefit: The proposed `default` expression adds considerable complexity to PHP's syntax. While it might solve some edge cases, I'm not convinced the benefits outweigh the added complexity. Our current methods (named arguments, null coalescing, etc.) already handle most scenarios effectively. 2. Principle of Least Astonishment: PHP developers are used to default values being implicitly used when arguments are omitted. Introducing an explicit `default` keyword changes this expectation and could lead to confusion, especially for newcomers to the language. 3. Type Safety and LSP: The ability to modify default values at the call site raises concerns about type safety. The RFC's example of potential LSP violations is particularly worrying. This could lead to subtle bugs that are hard to track down. 4. Code Readability: One of PHP's strengths is its readability. I'm concerned that `default` expressions, especially when combined with other operations, could make code harder to understand at a glance. 5. Performance Considerations: The RFC mentions using reflection-like mechanisms for `default`. Have we considered the performance implications, especially for high-traffic applications? 6. Inconsistent Behavior: The proposal suggests different behaviors for `default` in various contexts (e.g., function arguments vs. variadic args vs match expressions). This inconsistency could be a source of bugs and confusion. 7. Maintenance Burden: Implementing and maintaining this feature, with all its proposed restrictions and edge cases, seems like it would add a significant burden to the language maintainers. 8. Backward Compatibility: While the RFC claims no known BC breaks, changing the meaning of `default` in certain contexts could potentially cause subtle issues in existing codebases. I understand the motivation behind this RFC, but I'm concerned that it's solving a problem we don't really have, while introducing new ones. Perhaps we could explore alternative ways to address the specific use cases that motivated this proposal? For example, the `applyTheme` function in the proposal can be simply implemented as: ```php function applyTheme(?string $theme = null) { return new Config(...(isset($theme) ? [new $theme] : [])); } ``` This achieves the same result without having to call `array_filter` or rely on reflection, and without introducing a new language construct. What do others think? Am I overlooking some key benefits that would justify these concerns? Looking forward to hearing your thoughts, Cheers, Hammed --000000000000d397950621149500 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

H= i all,

I've been following the discussion on the Default Express= ion RFC, and while I appreciate the effort to introduce more flexibility in= handling default values, I have some significant concerns about this propo= sal. I'd like to share my thoughts and invite further discussion.
1. Complexity vs. Benefit:
=C2=A0 =C2=A0The proposed `default` express= ion adds considerable complexity to PHP's syntax. While it might solve = some edge cases, I'm not convinced the benefits outweigh the added comp= lexity. Our current methods (named arguments, null coalescing, etc.) alread= y handle most scenarios effectively.

2. Principle of Least Astonishm= ent:
=C2=A0 =C2=A0PHP developers are used to default values being implic= itly used when arguments are omitted. Introducing an explicit `default` key= word changes this expectation and could lead to confusion, especially for n= ewcomers to the language.

3. Type Safety and LSP:
=C2=A0 =C2=A0Th= e ability to modify default values at the call site raises concerns about t= ype safety. The RFC's example of potential LSP violations is particular= ly worrying. This could lead to subtle bugs that are hard to track down.
4. Code Readability:
=C2=A0 =C2=A0One of PHP's strengths is its= readability. I'm concerned that `default` expressions, especially when= combined with other operations, could make code harder to understand at a = glance.

5. Performance Considerations:
=C2=A0 =C2=A0The RFC menti= ons using reflection-like mechanisms for `default`. Have we considered the = performance implications, especially for high-traffic applications?

= 6. Inconsistent Behavior:
=C2=A0 =C2=A0The proposal suggests different b= ehaviors for `default` in various contexts (e.g., function arguments vs. va= riadic args vs match expressions). This inconsistency could be a source of = bugs and confusion.

7. Maintenance Burden:
=C2=A0 =C2=A0Implement= ing and maintaining this feature, with all its proposed restrictions and ed= ge cases, seems like it would add a significant burden to the language main= tainers.

8. Backward Compatibility:
=C2=A0 =C2=A0While the RFC cl= aims no known BC breaks, changing the meaning of `default` in certain conte= xts could potentially cause subtle issues in existing codebases.

I u= nderstand the motivation behind this RFC, but I'm concerned that it'= ;s solving a problem we don't really have, while introducing new ones. = Perhaps we could explore alternative ways to address the specific use cases= that motivated this proposal?

For example, the `applyTheme` functio= n in the proposal can be simply implemented as:

```php
function a= pplyTheme(?string $theme =3D null) {
=C2=A0 =C2=A0 return new Config(...= (isset($theme) ? [new $theme] : []));
}
```

This achieves the = same result without having to call `array_filter` or rely on reflection, an= d without introducing a new language construct.

What do others think= ? Am I overlooking some key benefits that would justify these concerns?
=
Looking forward to hearing your thoughts,

Cheers,
Hammed

<= /div> --000000000000d397950621149500--