Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:109260 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 93688 invoked from network); 24 Mar 2020 10:56:56 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 24 Mar 2020 10:56:56 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id A5BDC1804C4 for ; Tue, 24 Mar 2020 02:21:15 -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=-1.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,HTML_MESSAGE,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-vs1-f42.google.com (mail-vs1-f42.google.com [209.85.217.42]) (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 ; Tue, 24 Mar 2020 02:21:15 -0700 (PDT) Received: by mail-vs1-f42.google.com with SMTP id a63so10680732vsa.8 for ; Tue, 24 Mar 2020 02:21:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=7q2ho8XJHTTsYRJN/2ErV4jc/iyzO58Ibw5zE0fymOE=; b=Wee/liQ/yk1FXIasPID/6VyDDSq+VO3CT6ZDRqLIjhdRsXfzSGNSScFXWxSCHAvCMH KW3cQ6SIhhB3iwpRqEG7ahAUg7EOyWSeh7yh5wsFdmqqGJunlq09l11NccANEs84qwBM PP4eI0thHEazbUbgKoUlm4/pwd5COdulorTyFiA9FRbzUKg1ECGndrsdj9Fh8oP0XPNR 7tDAbdmfWEwOQexNvGbI17PWELR5oB2kOJkcAI00nCXaQVunXiN2pZcEwtdKzdsMLTn6 UcGgr/maN91JIw8+Rd2e+U2FXvSN2q7nH2yhUhdZqqIEiWkt2pgCXNa/hvJC0KgTvXJf qd1A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=7q2ho8XJHTTsYRJN/2ErV4jc/iyzO58Ibw5zE0fymOE=; b=JYVLri1NV8TOXPP6v4fuDH6nopgSaX5/TMDDhIy24+6GAgTRYSOcyg9OXvQ/J3aRJO wOFSxXoz/IWQbYZWCuE8gvpEHnPLacGD8diCdeRbSf75GT9sMzSvZCwa+Ux4jvB8I3FC Fr3D5SXFbn2pzFdNaYwBtuMpA/RAx5tHytBkmlVU21mKP7j9BIO/rwJ7Q0deR+Vbf2Rm WaqNHzUEEuHjqJSbp8DG53JGokoXB32Ve8K5eGLr+0641XIGnEgtnSumUgDhiFwR2szF T2RPkh5A0vU4ZXeq1lEVeeNtEKlsKQput/PCzyQSknVnId9uAVPdiQidNpRAWP4v3dCB bhgg== X-Gm-Message-State: ANhLgQ2xkP5bWOso/GKk/wkGyNyP2TSdCXBjdcKW8iJCMjNXhGgjFMm7 8wbYFdAkGSqsF/FiD1yiooVJBPyIrLUyuC+69Bg= X-Google-Smtp-Source: ADFU+vs7aMoJbsUbPu/LBPiJF/m6TBKxLtemaxGaP9s1VgvLKqgk5MqVAT1sxqv4vkaK08AhjcOUmZGUrcvlTOmaMX4= X-Received: by 2002:a67:20c1:: with SMTP id g184mr18064920vsg.178.1585041672823; Tue, 24 Mar 2020 02:21:12 -0700 (PDT) MIME-Version: 1.0 References: <1b781e1e-3f27-485b-ab47-5eeaf9496548@www.fastmail.com> <0af67f9d-ce2a-476f-abad-385080ce14e8@www.fastmail.com> In-Reply-To: Date: Tue, 24 Mar 2020 10:21:01 +0100 Message-ID: To: =?UTF-8?Q?Micha=C5=82_Brzuchalski?= Cc: Larry Garfield , php internals Content-Type: multipart/alternative; boundary="000000000000dce86b05a1964578" Subject: Re: [PHP-DEV] Improving PHP's Object Egonomics: A broad analysis From: kocsismate90@gmail.com (=?UTF-8?B?TcOhdMOpIEtvY3Npcw==?=) --000000000000dce86b05a1964578 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi Larry, In my opinion, one of the core assets of PHP is that it contains relatively few syntactic sugar compared to some other languages, e.g. C#. Maybe it's just me, but I believe it makes the code written in PHP easier to read. And I think this is what we should optimize for. Not for saving a few lines of code, but for making the code easier to read and understand. Now, if we had constructor promotion, we should search for properties both on the top of the class and in the constructor. And I agree with Micha=C5=82, this kind of code can= get out of hand of control very fast. That said, I don't think that declaring properties in the constructor is a good idea. It's also because many people (including myself) tend to write static methods first (I mainly use them as named constructors), so we'd either lose track of properties declared in the constructor or have to force a code style that puts the constructor to the top. Also, some IDEs (but PHPStorm for sure) can generate the constructor very easily from the declared properties. Speaking about the evaluation of "Write-Once Properties" and "Compound Property Visibility", I disagree in some regards. I'll start with the less important one: > Because the write-once state is preserved across cloning, it makes > Evolution worse. I think it's quite expected that properties won't be writable after cloning. That would be a very bad design otherwise. That's why I think your real problem is the opposite: that currently the clone operator is not prepared for this change. That's why I missed the "Rust-like cloning" (or the other clone variant that I presented in the "write-once property" thread) as the solution of the "Evolution" problem of "write-once" properties. My other problem with the evaluation of the "Immutability problem" is that it suggests that immutability is only an external concern, and it isn't a thing in the private/protected scope. Why do you think so? Currently (unfortunately) visibility is the only thing that can at some extent (in external scopes) control mutability in PHP. However, if we look at the problem from the type system perspective, visibility has nothing to do with it: we won't have any guarantee that a property is immutable even if we make it private. To be honest, my impression is that most of the problems you list (e.g. verbose constructor, bean problem, or even property accessors) mainly boil down to the verbosity of PHP (or the "visual debt" problem how some people calls it). As I wrote in the first paragraph, I don't think it's a bad thing. For example, if we had "compound property visibility" then we could separate read/write visibility of properties without using getters/setters (I think this is what you also wrote). If we had property accessors then besides the separation of visibility, we could have materalized properties or properties that validate themselves. Probably the syntax would become more concise, but effectively we would make methods from the properties. But I don't understand why is would be a good thing to have two types of methods? How should we decide if we should use normal methods or property accessors? I think the current situation is much better: use getters and/or setters to separate visibility of properties, and perform validation in setters if you need it. And I I still don't think that property accessors would solve the main use-case of "write-once" properties. Cheers, M=C3=A1t=C3=A9 --000000000000dce86b05a1964578--