Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:108028 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 6005 invoked from network); 8 Jan 2020 12:43:43 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 8 Jan 2020 12:43:43 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 2D2431804F4 for ; Wed, 8 Jan 2020 02:49:05 -0800 (PST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,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-io1-f44.google.com (mail-io1-f44.google.com [209.85.166.44]) (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 ; Wed, 8 Jan 2020 02:49:04 -0800 (PST) Received: by mail-io1-f44.google.com with SMTP id c16so2690713ioh.6 for ; Wed, 08 Jan 2020 02:49:04 -0800 (PST) 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; bh=87Qyc9u2l6d5u9N3QhETe73Jp0b+3b2jN5qsWxeAA9k=; b=ETaaLwy4Dw0iUYbqJNCse+cmUTSk5N7m99PsUN2giyYlpiWxjhD1oGfh2rVBGu5J66 9wf2sfNDg3Wcax9joSu+sLf1YMU+sEzzPSGf8DN2WV7ybG32UobL5w9750aLOAN/NCPw QXa+f+b8t27tT2jh+m3RkZ4QUlLdUWCGPkQMBlH1ytABSUIdOvaOx26YQJHHWBUTiArz 6O3uyUC6W9GiY3igk3LUAzQtdT6hTHMcYe5owPdAZv/bTkqXZa0rm7NY/BYGHG6NWjBn buYclteeJ84pjtWpzsnX1dMI9VBBFZk/weMXSfdEbI7ARRkoS9xzrXPbzdYMtsnLrh96 k4Cw== 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; bh=87Qyc9u2l6d5u9N3QhETe73Jp0b+3b2jN5qsWxeAA9k=; b=KQak6vmsqJesmbb30i2muTga/lcw0JZXXOEYvmHilhX6s45XDGwYoeCYPOcMCjhXiu Ugykd1evt1anjxGXeOexY65QKOr2l1aSp8Hzg3GYxPl+KirBQeYMWYrqJHN1ZiBRWDfK IXLLmUuVeQa96MTDFmTFRAKS5z558+N2BUZwlTbpBUkKxBgj8i5bFKA8B2ax3p8vYZKl NiOHafUP2vvtCoZ7GPRtc99aM0DnfDtUBsrsMV84wduIorpguuQdSIMt9d7JNqq2KNix rqk0ZTJcvscdREEr4b6fQpBH/bdkbjj0e0bJhV89CTEB1BmOG2V2gxXo2+vg5MNB8wpQ nzNw== X-Gm-Message-State: APjAAAWd+ffGqoB+agLgvn/AT7gX9343AWzQSn+2LgGaj7guxmRXjxsz cEEmQ0QqIQcdgUNFFFEaoQy6sygg2mts+2P49ctI/HUm X-Google-Smtp-Source: APXvYqxwc27tK0djGQi3Nu1VUPWIXRiVeEkoZB68t4dGeunU7flNwQZQ+8GV81D/Mo9+oRSsBlcf3bFCPsItiHzrco4= X-Received: by 2002:a02:864b:: with SMTP id e69mr3443493jai.83.1578480538595; Wed, 08 Jan 2020 02:48:58 -0800 (PST) MIME-Version: 1.0 References: <5e0d723f.1c69fb81.e2ae8.24e2SMTPIN_ADDED_MISSING@mx.google.com> <74F2DBFC-E63C-428C-A37F-2D0CEE15AD0F@newclarity.net> <53556dfb-44ce-f902-204c-9a7da9484a61@gmail.com> <65567C7C-CF0F-4562-8943-F1F302134B07@newclarity.net> <6f20bda1-eff6-631d-915f-d6bb149ee666@gmail.com> <93BA4B49-9D9A-4A41-83B3-8EC2564A70BF@newclarity.net> In-Reply-To: Date: Wed, 8 Jan 2020 10:48:47 +0000 Message-ID: To: PHP internals Content-Type: multipart/alternative; boundary="000000000000c9b633059b9ea3af" Subject: Re: [PHP-DEV] Initializing constants once, with code? From: rowan.collins@gmail.com (Rowan Tommins) --000000000000c9b633059b9ea3af Content-Type: text/plain; charset="UTF-8" On Tue, 7 Jan 2020 at 22:19, Mike Schinkel wrote: > I think you are taking one of my use-cases and over-focusing on it rather > than accepting it as just one of many applicable use-cases. > Yes, I dived quite deep into that one example, mostly because I was trying to understand why you picked it. I do think it's important though to demonstrate that a new language feature meets a real and common need, rather than just an interesting theoretical possibility. Again, those are my preferences. Yours can clearly be different. But unless > the PHP "charter" is revised to embrace "one way and only one way to > accomplish a given task" like the Zen of Python, my preference and your > preferences should be allowed equal weight. > That would be the case if the language didn't support either, and we were choosing between, but we're not. I'm arguing for using the existing features of the language to solve the problem, whereas you're saying we need to add a new way to do it. That requires a higher bar than "it's not objectively worse and I happen to like it". > That said, maybe I should be requesting that PHP constants be able to have > objects, too...? > If they can be initialised at run-time based on arbitrary code, it's going to be hard to avoid including that in the implementation, because at the moment constants are restricted not by types of value, but types of expression, so I'm not sure you could say at runtime "does this value look constant-y?". > > Or maybe everybody really wishes it had them, but nobody's come up with > an > > implementation that fits into the language design? > > Po-ta-to, po-tah-to; a past design decision really does not matter. It is > an example of a "sunken cost." > You've lost the context here. You said "Python did not feel there was a need"; I was saying maybe they thought there was a need, but hadn't found a solution. It's all beside the point anyway: PHP already has compile-time constants, so without a time machine, our discussion has to start from that basis. > > Then all the JS and Java examples aren't going to help your argument, > > because those are most definitely immutable variables, not compile-time > > constants extended with initialisation syntax. > > My argument has been and continues to be that that is a distinction > without a difference. > Your last e-mail seemed to say completely the opposite; maybe I misunderstood: > As for immutable variables, I see those as very useful to, but I think their use-cases are orthogonal to the use-case I was trying to address. I think immutable variables very much address the use cases you're trying to address, except for the additional requirement about which syntax access should use. > Besides, didn't you ask for examples and I gave you one from each of five > of the most common languages? It seems disingenuous to now try to argue the > examples I gave don't apply on reasons of technicality. > I asked for examples because it's useful to examine them and see how they're similar and how they're different. The "technicality" is that Java didn't introduce a syntax for compile-time constants and extend it with initialisation, they introduced a restriction which can be applied to any variable, and which when used in a certain way is roughly equivalent to a compile-time constant. That's a really significant difference, because it means that they inherit all the behaviours and syntax of variables, which PHP's constants currently do not. > > My point was that more assumptions will break if you widen the meaning of > > "constant" than if some variables are marked immutable. > > I'm all for taking those into consideration assuming we delineate them > concretely instead of just referring to them abstractly as a class of > unknown problems. > > So, what real-world specific concrete problems will this "widening" cause? > A couple of things come to mind: - tools that examine expressions involving constants for things like unreachable code, wrong types used, etc, would need to treat run-time-initialised constants specially - constants could now presumably be any type, including mutable objects, which is likely to break a bunch of assumptions > What would be interesting instead would be to have some kind of > developer-controlled pre-loading where classes could be marked to be > pre-loaded in some way. If we had those then one potential compromise > would be that constants could only be dynamically-initialized in pre-loaded > classes, which could significantly reduce Larry and your stated objection > since the initialization would happen at preload time and not page-load > time. > At the point where you have different pieces of code run at "pre-load" and "execution", that to me is equivalent to having a pre-processor that outputs OpCodes rather than PHP code (and thus is possibly easier to do things like present correct line numbers to debug tools). Running the pre-processor on preload sounds tempting, but we'd need some way to get input from the environment to the preloading routine, and would need to initialise enough of the VM's runtime state to allow code to be executed rather than just compiled. There'd also be cases like command-line unit tests where users would still need to mess around getting the environment right, just like with a traditional build step. It mostly boils down to "run build step automatically on server start", rather than actually eliminating the complexities of the build step itself. Regards, -- Rowan Tommins [IMSoP] --000000000000c9b633059b9ea3af--