Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:108019 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 26711 invoked from network); 7 Jan 2020 03:08:04 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 7 Jan 2020 03:08:04 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 1FFEC1804D1 for ; Mon, 6 Jan 2020 17:13: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=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HTML_MESSAGE,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL,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-yw1-f42.google.com (mail-yw1-f42.google.com [209.85.161.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 ; Mon, 6 Jan 2020 17:13:04 -0800 (PST) Received: by mail-yw1-f42.google.com with SMTP id n184so22742313ywc.3 for ; Mon, 06 Jan 2020 17:13:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=newclarity-net.20150623.gappssmtp.com; s=20150623; h=from:message-id:mime-version:subject:date:in-reply-to:cc:to :references; bh=BtZ46/6SHPrYVW6HcX0MVtsboGRPKEV+U9kbEq9hMZY=; b=OJSIAvPQEpEeWqOUwOLhWRbZDsiwbUo6t2RkkE0xyBstveLCApCYdDugVD51fgZ9m/ XseGd/PCJraXiZX43skpfRIgmPYEMDoLNpHNVrghC/RvDwXXYl4x9Z6yNEevSTBVrD6z Edjsn2sm8zg3w6Bpj+JSn+HjZSV1X9BI3gBRnLOumRWUXVR6RAhmHMvfaDPzI6D3XoWx 3jiIYxhHTi80ZTB/V6OXBxrsgeRVU/VW6xLIFwFOdvU1XemDmSTSvww/W76hqK68h8vP +LXAOMcqKGORwzP1iiO0mxOFicFOpY+3unTe8DZXIgWgYPqPfVtgequo3YSAQlyG+E7Z DV5g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:message-id:mime-version:subject:date :in-reply-to:cc:to:references; bh=BtZ46/6SHPrYVW6HcX0MVtsboGRPKEV+U9kbEq9hMZY=; b=XQcZZIrGMgjQ0OBFpz2ngKNGF1c++okLxI1KyQy/6F2DHa06to7zDdsiMh/+TymBJR VXRHJlDm4nfwF3H1TlEx6h8WsfVgNo/bA254Td9U8qcR2z9aVL2ybTtZMfCdd+Qz74wK ZufP1U24UX+rO0QmV1RlrmPvWcH9MY1pKO3YYY3ZxTg/zTgROIJ+w0YqSGxIsTIUpYTt QZXWOIVmG7+lKU54RhZFTdUQZR8zXsZnzySxam8GGEpzynATAQB+QfDa8gLgWZ6URBb9 m9lugpca6hg32m/3e37UvqTbwqFHz4cYnyzTHvQDCH2s8JGJyrxV8q+gKWDVb8wZCGft /frQ== X-Gm-Message-State: APjAAAUIUy+ziGhAXFU6jMu+K7q3rFIw7oktmTv62JpcK/qHqgBUJNFe 7wfvSD1f33EUxNo48QprIKuSbg== X-Google-Smtp-Source: APXvYqwDHAVI7jywxROPfZBbAnNplRThcY6VHJ9FV7JlIbMzP4dLcseIUh5jMTP/bz9dvr0LwNnm8g== X-Received: by 2002:a81:9243:: with SMTP id j64mr81069392ywg.513.1578359582306; Mon, 06 Jan 2020 17:13:02 -0800 (PST) Received: from ?IPv6:2601:c0:c680:5cc0:d059:ddab:12ae:4ac7? ([2601:c0:c680:5cc0:d059:ddab:12ae:4ac7]) by smtp.gmail.com with ESMTPSA id u136sm28706033ywf.101.2020.01.06.17.13.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 06 Jan 2020 17:13:00 -0800 (PST) Message-ID: <93BA4B49-9D9A-4A41-83B3-8EC2564A70BF@newclarity.net> Content-Type: multipart/alternative; boundary="Apple-Mail=_7CE767DC-DC3E-49D9-ABE7-EC0DAE28F8B5" Mime-Version: 1.0 (Mac OS X Mail 12.4 \(3445.104.11\)) Date: Mon, 6 Jan 2020 20:13:00 -0500 In-Reply-To: <6f20bda1-eff6-631d-915f-d6bb149ee666@gmail.com> Cc: internals@lists.php.net To: Rowan Tommins 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> X-Mailer: Apple Mail (2.3445.104.11) Subject: Re: [PHP-DEV] Initializing constants once, with code? From: mike@newclarity.net (Mike Schinkel) --Apple-Mail=_7CE767DC-DC3E-49D9-ABE7-EC0DAE28F8B5 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 > On Jan 6, 2020, at 4:59 PM, Rowan Tommins = wrote: > I'm still struggling to understand why you need multiple constants, = all mutable based on some other dimension. > If the ultimate goal is to know the name and branch of the *current* = environment, how do the constants help? At least two come to mind: 1. Guard clauses for code you only want to run in one environment and = not another. 2. Common code that is used by different websites. > We'll just have to agree to disagree here. I stand by the assertion = that "compile-time constants" are a well-defined feature, whose = restrictions are part of their definition and purpose. > That method is not actually a feature of constants, its abusing the = fact that everything is an object, so the *value* of a constant might = still be a mutable object. It's an interesting "cheat", but it's not = really a deliberate language feature. The .replace is not a deliberate language feature? > Unless I'm missing something, this isn't really related to anything = we've been discussing, it just happens to use the keyword "const". It is not exactly the same, but it is used to create immutable values = stored in variables, aka constants. Hence why I included. > Those links seem to say that Python doesn't have constants *at all*, = but you can emulate them in various ways. As such, you can give them = pretty much whatever behaviour you like, since you're defining the = language feature from scratch. Yes. IOW, Python did not feel there was a need for a compile-time = constant. > The biggest sticking point in my mind is your insistence that they = share syntax with constants, rather than variables. This means they can = only be used in static class or namespace context, not against an = instance. It's not an insistence per se, it is the use-case I am trying to = address. I can already use static variables, and the immutability is not that = important to me.=20 It's the desire to be able to start as statically declared constants and = evolve later to dynamically initialized. 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. > It also means *widening* the meaning of a construct, rather than = *narrowing* it: the "final" keyword in Java doesn't let variables do = anything new, it just restricts them; your proposed constant = initialization would allow constants to act in new ways, including = holding complex, mutable types. But isn't that often the point of new features; to allow for doing = things in new ways? > That's likely to cause confusion for both humans I often chuckle when I hear that something might cause confusion as an = argument against adding to PHP because it makes me think of PHP = generators, generator return expressions and Generator delegation! I assert that if we can add generators (and in the future, generics!) = then most anything we could add is going to be less confusing. :-) > and tools written based on the current concept that a constant can = always be computed at compile-time. My assumption is that the tool would simply be updated to recognize = which constants would be initialized at runtime. > The difference is that a Java-style "final variable" can have a single = value *per instance*, I cannot think of anything conceptual that would keep us from having = constants per instance, but I don't see a strong need for is so I did = not propose it. > I would be interested to hear more about why you think pre-processing = doesn't suit your use case. When I think of pre-processor, I think of textual substitution. It is = very difficult if not impossible to write textual pre-processing code = that is both reusable _and_ composible with pre-processing code that = someone else wrote. Thus if there are several header files in the wild, = you typically can only use one of them. I am still influenced by the words of Bertrand Meyer in the book where I = first learned object oriented programming "Object Oriented Software = construction" in his section on Composability: > "A method satisfies Modular Composability if it favors the production = of software elements which may then be freely combined with each other = to produce new systems, possibly in an environment quite different from = the one in which they were initially developed." > "Counter-example: preprocessors. A popular way to extend the = facilities of programming languages, and sometimes to correct some of = their deficiencies, is to use =E2=80=9Cpreprocessors=E2=80=9D that = accept an extended syntax as input and map it into the standard form of = the language. Typical preprocessors for Fortran and C support graphical = primitives, extended control structures or database operations. Usually, = however, such extensions are not compatible; then you cannot combine two = of the preprocessors, leading to such dilemmas as whether to use = graphics or databases." =46rom page 42: = http://web.uettaxila.edu.pk/CMS/AUT2011/seSCbs/tutorial/Object%20Oriented%= 20Software%20Construction.pdf = =20 Finally, a long time ago in a far away galaxy I was a Clipper developer, = and in version 5.0 they implemented a preprocessor to enable = user-defined commands. Many of us including myself jumped on them and = created some pretty horrific architectures, and then quickly found what = a nightmare they are when trying to combine them. -Mike --Apple-Mail=_7CE767DC-DC3E-49D9-ABE7-EC0DAE28F8B5--