Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:108027 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 60275 invoked from network); 8 Jan 2020 00:13:56 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 8 Jan 2020 00:13:56 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 19BA7180532 for ; Tue, 7 Jan 2020 14:19:09 -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=-1.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE, SPF_NONE 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-yb1-f180.google.com (mail-yb1-f180.google.com [209.85.219.180]) (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, 7 Jan 2020 14:19:08 -0800 (PST) Received: by mail-yb1-f180.google.com with SMTP id k5so663212ybf.8 for ; Tue, 07 Jan 2020 14:19:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=newclarity-net.20150623.gappssmtp.com; s=20150623; h=mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=nUnxgFV7ZDlZpNmYx05dAgvQCtEU1sa9QkAUHOgvYuw=; b=utmPRIrkVT/HJUin2LyuzeLMMVJJipmLi7yNclr+VNUkJxthyLJ3qM9arVRdaiWXYJ a0KJmGfB3X+xPUYH38ulXIc9PNz2BzD+lSWY5AJuieIArHXmDezh1m0H+FtMdLUrBI+Z nuKh9muuf/Paj3ElLbAZjh8UaHfpGEIr+/etGPYOlvGLuATRplkKittMMbqxsCzv1ufU /AjCP6DvN4yG8RY89VXGNV7BY1oPCIIXOoSj42ByD/xtzwdmDPpaAZcGpxxILUOO+ov3 yppDglKwxhviZs0GLEhIddWROoxLI8wnQ4Jiwy0eBKwFw/CLS5X1MaUGx820b5SxkzhX PbHQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=nUnxgFV7ZDlZpNmYx05dAgvQCtEU1sa9QkAUHOgvYuw=; b=PCWqsFwsvo3O7klRBomejXm2aMzi1/Bnph2oa7A4dWhjOQdPcLWJJC9bPjBQGgpJH8 PkrQl2zncnY7zXofV09LXZ8J+khTy4xI4F8TGrJK43AmuRtLDFPdFotvG8MIu7B6IYD0 yZbOfhHhQ5K2XXVR/lFqSVqhVOPjPpx9yMu1TlnBCCvGWe+b9DE/skH0TP+hJBUJ5ID6 45Utb9NKDvjkFbAVWdwSyMSrvuhazsQL1Yred7nXRs/HQxsEcY998NOv/ECpTqcEXkVS QNbXPMJAaBja52X9sOQtPEGxa8iZiOTsHcCQL7+TuOQzmwK2mBjxUGw9CL+kw3azO7mK 5Eog== X-Gm-Message-State: APjAAAVxmezA3MWnTOnTaBQxjSdBwlRYLEi4UYEB8O8Da97iLJSUaLH4 GhiP8FykIu3gkL5u6DV+Ypamrg== X-Google-Smtp-Source: APXvYqyJuCcoyoWGx6EQXYRfrkx1cute6XXltP6XO4KGHn/rMrL8tYXCJKVqfWNSmCdK77pDF0vbdw== X-Received: by 2002:a25:ca10:: with SMTP id a16mr1569608ybg.280.1578435545956; Tue, 07 Jan 2020 14:19:05 -0800 (PST) Received: from ?IPv6:2601:c0:c680:5cc0:bd01:d442:6075:bd1c? ([2601:c0:c680:5cc0:bd01:d442:6075:bd1c]) by smtp.gmail.com with ESMTPSA id s5sm465290ywb.34.2020.01.07.14.19.04 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 07 Jan 2020 14:19:05 -0800 (PST) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 12.4 \(3445.104.11\)) In-Reply-To: Date: Tue, 7 Jan 2020 17:19:03 -0500 Cc: PHP internals Content-Transfer-Encoding: quoted-printable Message-ID: 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> To: Rowan Tommins X-Mailer: Apple Mail (2.3445.104.11) Subject: Re: [PHP-DEV] Initializing constants once, with code? From: mike@newclarity.net (Mike Schinkel) > On Jan 7, 2020, at 5:15 AM, Rowan Tommins = wrote: >=20 > It seems to me that there are two different concerns there: > > So at its simplest, I would write something like this: >=20 > class Environments { > const PRODUCTION =3D 4; > const STAGING =3D 3; > const TESTING =3D 2; > const DEVELOPMENT =3D 1; >=20 > public static $branches =3D [ > self::PRODUCTION =3D> 'master', > self:: STAGING =3D 'stage', > self:: TESTING =3D 'test', > self:: DEVELOPMENT =3D 'dev', > ]; > } 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. That said, I would not want to implement as you propose. I prefer to = have values that can change be declared at the top of the class as = constants where they are _not_ obscured by extra syntax =E2=80=94 as in = your example with brackets, self::, and fat arrows =E2=80=94 so as to = make them the most scannable. 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. > It's not a feature of constants, it's a feature of strings and arrays, > because they are implemented as objects. The same trick would be = possible > in PHP if constants could have objects as values: Even so, in Ruby you can define constants dynamically at runtime. That said, maybe I should be requesting that PHP constants be able to = have objects, too...? > 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."=20 What should only matter is what makes more sense moving forward. > If we take these two statements really literally, you can do = everything you > want already: Except there was a third statement you did not reference:=20 - "My primary goal is to be able to modify constants in _existing_ code = to be initialize at runtime to support evolvability/refactoring." > 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. 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. > 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? > For the record, I think generators are a really neat feature, but > absolutely hate that they are declared with the "function" keyword, = and > hate that they reuse the "return" keyword for "set final value". >=20 > So, yes, that's a good example of something that breaks people's > expectations of what keywords mean, and I think that's a bad thing. I was not pointing out the naming, I was pointing out how confusing the = features are to understand and use regardless of naming. But I am not arguing that we do not including confusing features. To the = contrary, I think we should include more power in the language, even in = places it might be confusing.=20 Just not Ruby-level power a.k.a. ability to completely redefine the = language level of power. :-D > I'm not saying it's impossible to account for it, I'm just saying = there may > be a lot of tools out there which would need to be updated. Saying = "simply" > doesn't make it so! That can be said about every language enhancement, so as an argument = against a feature it feels a bit contrived. > I was thinking much more abstractly: some code of some sort that runs = as a > separate build step, and produces some kind of output that can be > referenced cheaply at run-time. >=20 > In particular, I was imagining the pre-processor being fully aware of = the > language's syntax, and operating at the AST level. You could view it = as an > extension of compiler optimisations: explicitly saying "run this = before you > even deploy to the server, the result will never change". >=20 > The output to PHP is necessary for the same reason client-side = languages > are transpiled to JavaScript - it's the language spoken by the target > run-time. If we could treat OpCodes as a stable target, like .NET CLI, = or > Java bytecode, it could target that instead, but it wouldn't actually = make > much difference to the operation of the pre-processor. There is of = course a > side-effect that the resulting PHP code can be read by a human, making = it > easier to debug. After posting my objection to pre-processing I remembered there was = another reason I object to pre-processors that is even more significant = than lack of composibility. And my objection extends to all the = transpiring being done with Javascript and CSS too, although I put up = with those because the community has mitigated some of the worst = problems and because so many developers have embraced them. The other objections I have to pre-processing: 1. It adds a build step to testing. PHP currently does not need a build = step and so the code-run-test cycle is not interrupted by a build step. 2. Build steps are non-trivial to set up and keep running. The front-end = developers I work with are always having some kind of problem with their = build process. 3. The source is no longer the production code. This means line numbers = and possibly other things in the error log no longer match the source = code. 4. Debugging is much harder. For PHP, XDEBUG does not understand = preprocessed code.=20 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. -Mike