Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:115439 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 37926 invoked from network); 16 Jul 2021 11:24:05 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 16 Jul 2021 11:24:05 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 4B8D9180089 for ; Fri, 16 Jul 2021 04:48:19 -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.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,FREEMAIL_REPLY, 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-Virus: No X-Envelope-From: Received: from mail-yb1-f174.google.com (mail-yb1-f174.google.com [209.85.219.174]) (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 ; Fri, 16 Jul 2021 04:48:18 -0700 (PDT) Received: by mail-yb1-f174.google.com with SMTP id c16so7627945ybl.9 for ; Fri, 16 Jul 2021 04:48:18 -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=qVWYlnA3yeSC6cAPpEDs2UoynFEp8nAksTRofhE+ax4=; b=kUvvWbFPZmzfN0r9u0xJuP3fNyLN6Ko3dgMhve4mx1UpoKScWieIDzOpxWWPVnePKP 9Bz0TeTSeGYYZijHU66wxhQtzlZobE5sbcv+Ytx8KIcXOgbjDt44LPWfoddrvZNf5Y+l 9NvdHjLjClmmDWgyUAkiCx3FfHsl5Or6yw2zPofr1IPRdXoeRk7uzb1sikl5CtRwp3jY IP7xVVym1TBmEnCkv/ugSqED81fwLEGZLj8PlW8PJjp4pUGA51RN7yOM+F7r+RdXMRj2 8vNis4PbMLJWroxGVeYdo48AKgRZWnWLQSFtbXZFRcN99VQVlojPAuxlq/WKiAionD3V nz4w== 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=qVWYlnA3yeSC6cAPpEDs2UoynFEp8nAksTRofhE+ax4=; b=BxysbMELmaTrzluIUsLw8sGIV60238oEacDGeae+Ep9uOjgEfy41lIsKddB36RZRxw 8NMB71dqL9t3qWMzGxf0mvihmd0Rec7gk5egpJ6mBhBKb8jUQgS0TuUKRZQSf6U67igF Mc5q1KIs4WbYzEk4tTS6M4I3Oxm1mm9NCdmzlH82ghsxTrKJPvR8YyGdYkr5Kvlt7/ze XsuDmIpYecvPludKL0MGZjjEx0xM1R8NEnN2Ggi74fudA2xy2TY7OIuxpSpLQZg/sKhs U6JmilfHLM+1nT2MIyXuSU38/izWKIetesSrrzii2bOV347lmPG4fMr+HES1/stSM2l0 BEow== X-Gm-Message-State: AOAM531Qw/g/TWehSouwj+G/zLszkOG4/I46GwIG+TP8gAwnBFHmn+Hr /7I+GmRbN/fuyiURhiyVj6RRhubu7E6erRs8CR8= X-Google-Smtp-Source: ABdhPJxp3E8xIeh1Gw4tN13/oFy1vN/PeOcM0WGl/OhiKvz2r6UWeGpd4fnvFykS6Mcl+K7RrS74HOayWjOW5c+E168= X-Received: by 2002:a25:d0cc:: with SMTP id h195mr12730941ybg.498.1626436098126; Fri, 16 Jul 2021 04:48:18 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Fri, 16 Jul 2021 14:48:07 +0300 Message-ID: To: Bruce Weirdan , Nikita Popov Cc: PHP Internals Content-Type: multipart/alternative; boundary="000000000000e0f5ea05c73c29ac" Subject: Re: [PHP-DEV] Readonly properties - immutability by default From: zsidelnik@gmail.com (Eugene Sidelnyk) --000000000000e0f5ea05c73c29ac Content-Type: text/plain; charset="UTF-8" @Nikita Popov I'm not sure what you mean by saying this: > We're always explicit at the declaration site, it's const FOO, function foo, class Foo etc Regarding your message > Here mutability is decided by single $ character in the declaration, which doesn't have a particular obvious connection to mutability. Yes, that is not really obvious about property mutability when we look at the code. I think it is probably better to rephrase it into something like: New way of properties definition without dollar sign. Not only do we remove dollar sign, but these properties can not be reassigned. Looking from this perspective we are trying to improve code quality and developer experience. Using immutability (as well as type-hints with strict typing) makes code less error prone. This should be promoted in the PHP community. What I want to say is: good things should be easily done, easier than things which are more error prone. Again, about explicitness and obviousness. Imagine (just for a second) that all existing properties are immutable by default. Then someone submits RFC to add mutability for them. It is accepted to add a new keyword like this: ```php mutable public string $bar; ``` Hence I mean: currently we have one default option (mutable properties) from 2 options. Why do we need to create such a long keyword just to use readonly properties (if immutability is better than mutability)? Regards, Eugene On Fri, Jul 16, 2021 at 1:13 PM Bruce Weirdan wrote: > On Fri, Jul 16, 2021 at 9:45 AM Eugene Sidelnyk > wrote: > > > Readonly properties are really useful for DDD, where everything is going > to > > be immutable. It promotes best practices. However for people to use it, > > syntax should be concise and brief. > > If every property of the class is readonly it would probably be better > to declare that with a class modifier. > > E.g. > > ```php > readonly class Entity { > public int $count; > public string $data; > } > ``` > > Though `readonly` doesn't look like a perfect fit in that position to me. > > -- > Best regards, > Bruce Weirdan mailto: > weirdan@gmail.com > --000000000000e0f5ea05c73c29ac--