Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:123988 X-Original-To: internals@lists.php.net Delivered-To: internals@lists.php.net Received: from php-smtp4.php.net (php-smtp4.php.net [45.112.84.5]) by qa.php.net (Postfix) with ESMTPS id E31E91A009C for ; Fri, 28 Jun 2024 14:05:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1719583612; bh=+wH0qQ7v0ij86Iu6B5kMQ39eBF6zaJ3gmIaUU9pLrCs=; h=Date:Subject:To:References:From:In-Reply-To:From; b=m1hUhBKugj/LBBLBDTWUf0y3TyDVAQYeFw0uuqSgvaf33JcohSxafYSi6E30uBVdX lVzEMcp+e7CX4y5lgNlAU+CyQlv2EGTFMxAP9774Jyex2GHNKOOP2pmJmIM2SF6r++ pb/dCjpBPmzP1Osd5As5j0nMVBUmp8mE3DyCIXoOooMYCDgOA3ThFOrSZC9jHqc6EQ QiJDPG3hFteJJ5vX5wI3n+17hlwCoSbpbil+D5tP0Gkdh7FxD/FzYBH2zXKiIUHAEx B9r9tuZd2mGvfT+Tn5Pce4weB8mHSCJt7a3lz8sAlAm2uItGoceF2Lx+M8VdPOoQ2j ilcMhUu//DgbQ== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id F26191806AE for ; Fri, 28 Jun 2024 14:06:50 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=0.6 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,HTML_MESSAGE, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: Error (Cannot connect to unix socket '/var/run/clamav/clamd.ctl': connect: Connection refused) X-Envelope-From: Received: from mail-wr1-f51.google.com (mail-wr1-f51.google.com [209.85.221.51]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Fri, 28 Jun 2024 14:06:50 +0000 (UTC) Received: by mail-wr1-f51.google.com with SMTP id ffacd0b85a97d-36740e64749so432060f8f.0 for ; Fri, 28 Jun 2024 07:05:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=seld.be; s=google; t=1719583530; x=1720188330; darn=lists.php.net; h=in-reply-to:from:content-language:references:to:subject:user-agent :mime-version:date:message-id:from:to:cc:subject:date:message-id :reply-to; bh=WcH3P1SfI9OR4AuGpYgUTXQOK8dmOMakXUMorvCcmX8=; b=cgnXxmxiftruzXe6LWrbojX2fucKfTFmexpyACZlJ0NsgTzy+4R7Ez5t6IJP3hkBnc 6jp/mZEFz98LwKWYYBPEjDMGgCk5TKxEigEYXyoEk0vgqDgm+j2hKiiABJB08e8t+zz1 9ofS4QB2JYsmGpzEUjyNx1yEk1hTGoRpa0Nxa1OK3MRVZW0PYfwx4kRPt5VWMJE7QXPN Ds+vpXaRfx1td4eptsAB+ZjbBFgpbeXc3yg5INIvyg2fMh2XrB04prILEG2nq4UzF7Ei lN1pnif+Yxuu0U+xIrHsSDvKoBRhqLRzhoQuCTWqJfjSaZjMV2lPhApY0dvzSCmYHkRi 6q8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719583530; x=1720188330; h=in-reply-to:from:content-language:references:to:subject:user-agent :mime-version:date:message-id:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to; bh=WcH3P1SfI9OR4AuGpYgUTXQOK8dmOMakXUMorvCcmX8=; b=NulVn3RhOJmfNmEYcwEwLcz/aGr74vrAlRzNV6fv29nKYsQzcZe2Op/RDNOxYBuXjE 8LLLsnr29SZfOi4BGH4c/z9UsGP2ShBzVHLVCAuEgKHkxmGufPNc/0uOJO5uI0blyaGQ MgijfDToQOiQU54tykm/M0gf1bxJEnQ2f8JiIxKfez0x2PpwiL6ObanEqGI+FU3kqOnm KIlEaBrfnZQXt697ZrfLk5vLPAB1rqJv9eeyCQAFMfA+QBoDpAd9c4GTmxMprdW6feDe NPr7ISiPu/S9GDKBuVBGdtsoBgrS+eRICNrBQ0X+/R4R7V6yaSXzhF8akNwqVdzVsBRy Wthw== X-Gm-Message-State: AOJu0YyKmNwLNuAToOlaD+wo/clv/On9gTTTo2gjfMDvdRmo1g/w0kgE iyPf8bPSTAY8R94e5Q9HzpPnUL3Nvkmrat9pgJ7QIO7p+owqW+ZegUiY5jZWHEWM8hEWsVk5l4u 9yI0= X-Google-Smtp-Source: AGHT+IH0jopzesb7gYvcS4vCyb5IiMmgpQeszHjp1dKRR303U5BZ9GUkeIPjL+O9GmTp8PyyckwGZA== X-Received: by 2002:a05:6000:1fa7:b0:365:32e0:f757 with SMTP id ffacd0b85a97d-366e96b22acmr14801779f8f.50.1719583529591; Fri, 28 Jun 2024 07:05:29 -0700 (PDT) Received: from ?IPV6:2a02:168:4b6e:0:806b:305a:4985:4848? ([2a02:168:4b6e:0:806b:305a:4985:4848]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3675a0cd5fcsm2410600f8f.11.2024.06.28.07.05.27 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 28 Jun 2024 07:05:27 -0700 (PDT) Content-Type: multipart/alternative; boundary="------------lf1hyf0ZzTy35xa6VO96OCrl" Message-ID: <1843d9ca-ac3d-408a-b018-9181ed03a6c5@seld.be> Date: Fri, 28 Jun 2024 16:05:25 +0200 Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PHP-DEV] [Initial Feedback] PHP User Modules - An Adaptation of ES6 from JavaScript To: internals@lists.php.net References: <1f556e18-cefb-4a15-b96b-08118e48610c@app.fastmail.com> Content-Language: fr In-Reply-To: <1f556e18-cefb-4a15-b96b-08118e48610c@app.fastmail.com> From: j.boggiano@seld.be (Jordi Boggiano) This is a multi-part message in MIME format. --------------lf1hyf0ZzTy35xa6VO96OCrl Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit First of all a quick note for the OP: I am all for it in general, but I don't think copying the entire JS module system one to one makes sense. It contains a lot of compromises and mistakes that we should absolutely learn from as well as the good things they did. On 2024-06-28 00:41, Larry Garfield wrote: > Which of these are we trying to solve? (Solving all of them at once is > unlikely, and some are mutually-incompatible.) > 1. Adding a "strict pedantic mode" without messing with existing code? > 2. Package-level visibility (public, package, protected, private)? > 3. Avoid name clashes? > 4. Improved information for autoloaders and preloading, possibly making class-per-file unnecessary in many cases? > 5. A larger scope for the compiler to analyze in order to make optimizations? > 6. Package-level declares, inherited by all files in the package? > 7. Something else? I agree with most of your analysis, and IMO Package-level visibility is the main direct win, with a larger scope for JIT optimization coming later. It would however be very tempting to bake in 1, and remove a bunch of things which are not removable from the language at large due to BC, as that might be a once in a lifetime opportunity. Some features make JIT optimizations nearly impossible (Nikita had a list somewhere.. but the main one if probably killing references). The autoloader information to be honest I am not sure how important this is. For everyone not wanting to do class-per-file, note that you can just use "classmap" autoloading in Composer. It is anyway the most performant option at runtime [1]. The only catch is you have to re-dump the autoloader when adding new classes/files to make them discoverable. But I think everyone's kinda too stuck on PSR-4 because it is a standard. > Do we want: > > 1. Packages and namespaces are synonymous? (This is roughly how JVM languages work, I believe.) > 2. Packages and files are synonymous? (This is how Python and Javascript work.) > 3. All packages correspond to a namespace, but not all namespaces are a package? > > And given the near-universality of PSR-4 file structure, what impact would each of those have in practice? (Even if packages open up some new autoloading options and FIG publishes a new PSR for how to use them, there's only a billion or so PSR-4 class files in the wild that aren't going away any time soon.) My gut feeling is we want 3, but I'm sure there's a debate to be had there. I'd go for 3 as well. Every package having a single root namespace is probably true of 99% of packages due to the PSR-4 autoload root. Sub-namespaces are discretionary. [1] https://getcomposer.org/doc/articles/autoloader-optimization.md -- Jordi Boggiano @seldaek -https://seld.be --------------lf1hyf0ZzTy35xa6VO96OCrl Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 7bit

First of all a quick note for the OP: I am all for it in general, but I don't think copying the entire JS module system one to one makes sense. It contains a lot of compromises and mistakes that we should absolutely learn from as well as the good things they did.

On 2024-06-28 00:41, Larry Garfield wrote:

Which of these are we trying to solve? (Solving all of them at once is unlikely, and some are mutually-incompatible.)
1. Adding a "strict pedantic mode" without messing with existing code?
2. Package-level visibility (public, package, protected, private)?
3. Avoid name clashes?
4. Improved information for autoloaders and preloading, possibly making class-per-file unnecessary in many cases?
5. A larger scope for the compiler to analyze in order to make optimizations?
6. Package-level declares, inherited by all files in the package?
7. Something else?

I agree with most of your analysis, and IMO Package-level visibility is the main direct win, with a larger scope for JIT optimization coming later.

It would however be very tempting to bake in 1, and remove a bunch of things which are not removable from the language at large due to BC, as that might be a once in a lifetime opportunity. Some features make JIT optimizations nearly impossible (Nikita had a list somewhere.. but the main one if probably killing references).

The autoloader information to be honest I am not sure how important this is. For everyone not wanting to do class-per-file, note that you can just use "classmap" autoloading in Composer. It is anyway the most performant option at runtime [1]. The only catch is you have to re-dump the autoloader when adding new classes/files to make them discoverable. But I think everyone's kinda too stuck on PSR-4 because it is a standard.

Do we want:

1. Packages and namespaces are synonymous?  (This is roughly how JVM languages work, I believe.)
2. Packages and files are synonymous?  (This is how Python and Javascript work.)
3. All packages correspond to a namespace, but not all namespaces are a package?

And given the near-universality of PSR-4 file structure, what impact would each of those have in practice?  (Even if packages open up some new autoloading options and FIG publishes a new PSR for how to use them, there's only a billion or so PSR-4 class files in the wild that aren't going away any time soon.)  My gut feeling is we want 3, but I'm sure there's a debate to be had there.

I'd go for 3 as well. Every package having a single root namespace is probably true of 99% of packages due to the PSR-4 autoload root. Sub-namespaces are discretionary.

[1] https://getcomposer.org/doc/articles/autoloader-optimization.md

-- 
Jordi Boggiano
@seldaek - https://seld.be
--------------lf1hyf0ZzTy35xa6VO96OCrl--