Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:111888 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 14952 invoked from network); 17 Sep 2020 18:13:35 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 17 Sep 2020 18:13:35 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 52F6B18053F for ; Thu, 17 Sep 2020 10:22:15 -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=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from srv015.mail.ichtushosting.com (srv015.mail.ichtushosting.com [159.69.182.195]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Thu, 17 Sep 2020 10:22:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=stitcher.io ; s=default; h=To:References:Message-Id:Content-Transfer-Encoding:Cc:Date: In-Reply-To:From:Subject:Mime-Version:Content-Type:Sender:Reply-To:Content-ID :Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To: Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe :List-Post:List-Owner:List-Archive; bh=xXwQ+u6R3zG4kslgeCx8WH8Eubcze5t5V1zTKzhlw2k=; b=etW+S08B0L33YESe40oV6yVezb G+DCONWh8lbWybdn+hYVxl6XQuMRuqLSQturyXcmm3oiCUNoMQo5oJ7ngoLPzngPCDAcAzfr5ht4t vjoPV0KlYAM/F/CJ6txcYFT+Mrk8hitaRvCX4KKy27AtZKzpl38QaCVk6Ig8H5QwXyY1A4r2nTmDV xpkIfQk442fuQNua9bA04FY+uQviu2M21tSkA/rEhiJCfrsnTyiiqes//FzwKXp6ZMSg/BS/bZWMm W22qufZ4U72lv7wUpwZOUeHXRTVGHs5OcH6IMCzmOVlCxWOk4mWaqfSzy/q/mRD+vitZpONcvakhI ATsQq2nQ==; Received: from srv020.mail.ichtushosting.com ([78.46.213.219]) by srv015.mail.ichtushosting.com stage1 with esmtp (Exim MailCleaner) id 1kIxbm-0007Yh-PB from ; Thu, 17 Sep 2020 19:22:11 +0200 Received: from ptr-fq9pjpjoj2u95w9lb54.18120a2.ip6.access.telenet.be (ptr-fq9pjpjoj2u95w9lb54.18120a2.ip6.access.telenet.be [IPv6:2a02:1812:c3c:3a00:edce:f36d:6feb:e4a8]) (Authenticated sender: brendt@stitcher.io) by srv020.mail.ichtushosting.com (Postfix) with ESMTPSA id 020543EBDA; Thu, 17 Sep 2020 19:22:09 +0200 (CEST) X-MailCleaner-return_path: brendt@stitcher.io X-MailCleaner-sender_address: brendt@stitcher.io X-MailCleaner-recipients: george.banyard@gmail.com, internals@lists.php.net X-MailCleaner-SPF: pass Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 13.4 \(3608.80.23.2.2\)) In-Reply-To: Date: Thu, 17 Sep 2020 19:22:09 +0200 Cc: PHP internals Content-Transfer-Encoding: quoted-printable Message-ID: <746FF807-02E2-4CD6-8EDF-1286CF1B021A@stitcher.io> References: <09DE673B-71B7-4C8E-A795-900B51F8E476@stitcher.io> To: "G. P. B." X-Mailer: Apple Mail (2.3608.80.23.2.2) X-MailCleaner-TrustedIPs: Ok Subject: Re: [PHP-DEV] The case for transpiled generics From: brendt@stitcher.io (Brent Roose) Hi George Thanks for the reply! > On 17 Sep 2020, at 14:34, G. P. B. wrote: >=20 > Hello Brent, >=20 > I'm going to make the argument I've already done on Reddit once [1], = IMHO > TypeScript is just a nicer pipeline for a preprocessor and a static > analyser and not a language per say. >=20 > Let me explain with a simpler example than generics, adding immutable > objects to PHP without native language support using a preprocessor = and > Psalm as the back-end for static-analysis. It would be rather trivial = to do > a search-and-replace of the word immutable and replace it with /** > @psalm-immutable */ at the (currently non existent) preprocessor level = then > run Psalm and have it shout at you if "you are doing it wrong"TM. > Now bundle the two tools into a nice CLI command run TypePHP = root_of_project > and voil=C3=A0 support for immutable by just writing >=20 > immutable class Foo {} >=20 > And I'm fairly certain that one can achieve support for generic = templates > in the same way, probably harder than adding support for immutable = objects. > It is also possible to have various back-ends for the static analysers > which would change the doc-annotation to the one understood by the = analyser > asked. >=20 > Most importantly this can be done purely in PHP and distributed as a > composer package. > Therefore needing no support from the language itself, thus this can = even > work in PHP 7. Preprocessing PHP has been done [1], and the reality is that it didn't = work. Not because it's technically impossible, but because there's no = tooling around it: no IDE integration and no static analysis. The pre = project actually tried developing a plugin for PhpStorm, which failed = due to plugin API limitations. Tooling and IDEs tend to follow the = language spec, because there's no way around it. That power lies within = the PHP project, and no one else in the community has the same amount of = influence. >=20 > As such I see no benefit in supporting generics at the language level = if > they don't have any runtime checks. Like I said in my mail: it's not about being able to achieve a specific = kind of functionality =E2=80=94 static analysers already support = generics =E2=80=94 it's about giving developers an easy, integrated way = of writing them, with as less overhead as possible. I think most new = features added to PHP these days are a testament to that mindset =E2=80=94= I've already mentioned them in my previous post. >=20 > Best regards >=20 > George P. Banyard >=20 > [1] > = https://www.reddit.com/r/PHP/comments/i9h1v8/considering_php/g1h9umy?conte= xt=3D3 King regards Brent [1] https://preprocess.io/#/