Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:121400 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 82043 invoked from network); 18 Oct 2023 15:38:06 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 18 Oct 2023 15:38:06 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 247DE1804B0 for ; Wed, 18 Oct 2023 08:38:06 -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,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE 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-oo1-f45.google.com (mail-oo1-f45.google.com [209.85.161.45]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Wed, 18 Oct 2023 08:38:05 -0700 (PDT) Received: by mail-oo1-f45.google.com with SMTP id 006d021491bc7-581b6b93bd1so2015778eaf.1 for ; Wed, 18 Oct 2023 08:38:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1697643485; x=1698248285; darn=lists.php.net; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=7+wY0N0LrzuWIrb7qjPaxXi/1PQMEvHJPjcA/Ij8th8=; b=A9AciVsOYJ50F+FQd/KmME9pOybql6gt2PZRR5Ng816I145Mg56Z0ZxYLV5WlGZUja DH1wMbcmia4VgZ/TMIevmwUn0SzjHacA8FCnWsoMx4G11MNi/AXeBi01KYL068r4214o jM3sHVs+Vqacrc8XSqXkCTE4ZIvTFJpQxCW8tRN/2cbC/BjADTZTbsmbGPDAJw+h2BU5 HjM3sXWEWJ19djkBk4xNj8gBJteTkfqNWeZsH2H1sTKzP5IDvmPreQKyOxbfgyR8rtLe RWlAJull2Bi7+I7+oAQpMljiSwH93s1D8EtvWFMYWPGifbRPD/qSm8tWQFQbUtgC3GTP mG9A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697643485; x=1698248285; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=7+wY0N0LrzuWIrb7qjPaxXi/1PQMEvHJPjcA/Ij8th8=; b=xNBM+rWL0ekun2WHOxvm7/1s16ZljfaG1xh4tDRINN/vokv3mDklH3XjKL+y0THbPJ OrQP/TVx7H26Ww3gFuMaxqnTvijY+gT7P2KxcQqrFhc/q8Hy1rfnb+WAnpGQUVUCy1IV hVEM7xatHlM/ihtat7R6302gnJd4E0DAer+1i0xHC/D0KDryvOCI0kCrpQw2mQ8WjagV U0MRf5ZHkWqJCUizIlQZaeu9QcE8TueqVp6v5h90XMDRK1Jj5HRSgBhKccVoJHvyReKK Umlhm6VKkJB5YllmnVAjAqdfhLEi1uZaO8UFVwHB+yEt1G6B/6T8T8leoFJl0nNWy8E7 vWEQ== X-Gm-Message-State: AOJu0YztTrAlYNz0oG2R2L1hIOCxk3bdYYRKpvd7sN10gsR1d6li2L+U gx+/6QOo256LCARmy/5iIzhGGsO/j32tV5fIQNnk/LPUs18= X-Google-Smtp-Source: AGHT+IHs0McH+x5frAiYdqhacJpjixqQNH309mt09cgQufh3I/+9yodNnxGfZmGJ45MoXnEw/BtxcFX6D4R1xB5YnnY= X-Received: by 2002:a4a:4302:0:b0:57b:a92a:ece9 with SMTP id k2-20020a4a4302000000b0057ba92aece9mr5203552ooj.6.1697643484867; Wed, 18 Oct 2023 08:38:04 -0700 (PDT) MIME-Version: 1.0 References: <9d5388fa-a5a5-4fa5-81ff-16f6670f80b6@gmail.com> In-Reply-To: Date: Wed, 18 Oct 2023 17:37:53 +0200 Message-ID: To: Deleu Cc: =?UTF-8?Q?Olle_H=C3=A4rstedt?= , Rowan Tommins , internals@lists.php.net Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] Previous discussions about generics syntax only? From: landers.robert@gmail.com (Robert Landers) On Wed, Oct 18, 2023 at 3:47=E2=80=AFPM Deleu wrote: > > On Wed, Oct 18, 2023 at 4:14=E2=80=AFAM Olle H=C3=A4rstedt > wrote: > > > 2023-10-17 21:39 GMT+02:00, Rowan Tommins : > > > On 16/10/2023 15:08, Olle H=C3=A4rstedt wrote: > > >> Hello internals, > > >> > > >> Was there a previous discussion about the pros/cons of adding only t= he > > >> syntax needed for generics, but not the functionality? So static > > >> analyzers could use it, instead of docblocks. I looked at externals.= io > > >> but couldn't find anything specific. > > > > > > > > > Hi Olle, > > > > > > Since I haven't seen it expressed quite this way in the previous > > > discussion, I'd like to highlight what I think is a major downside to > > > this approach, at least as commonly proposed: > > > > > > Using the same syntax for type information that is guaranteed to be t= rue > > > (existing run-time checks) and type information that is "advisory onl= y" > > > (new checks for optional static analysis) means users can no longer h= ave > > > confidence in that type information. > > > > > > This is one of the interesting things about the compromise over scala= r > > > types - if you see a declaration "function foo(int $bar) { ... }", yo= u > > > *know* that $bar will be an int at the start of every invocation of t= hat > > > function, regardless of which mode the calling code uses. I think add= ing > > > exceptions to that certainty would be a bad direction for the languag= e. > > > > > > On the other hand, I can see a "third way": if the problem with curre= nt > > > static analysis conventions is that they have to be parsed out of a > > > string-based docblock, we can provide *dedicated* syntax, without > > > unifying it with the standard type syntax. For instance, some of the > > > earlier discussions around introducing attributes suggested reflectio= n > > > expose the AST of the attributes arguments, rather than the resolved > > > expressions, allowing them to act a bit like Rust's "hygienic macros"= . > > > If that was added as an optional mode, you might be able to do someth= ing > > > like this: > > > > > > #[RawAttribute] > > > class GenericType { > > > public function __construct(AST\Node $typeInfo) { ... } > > > } > > > > > > function foo(#[GenericType(int|float)] array $foo) { > > > // array is the type guaranteed by the language > > > // static analysis libraries can get the GenericType attribute f= rom > > > reflection and receive an AST representing the type constraint int|fl= oat > > > } > > > > Not sure readability is improved here compared to existing @template > > annotations. ;) > > > > Olle > > > > I won't be participating much about this discussion because I lack > expertise to add too much. I just wanted to voice a small (and defeated) > minority of PHP developers that don't want/care for Generics. I've been > working with Typescript lately and I see generics only being useful for > library code and even then when I end up writing some valid Generics stuf= f, > Typescript verbosity becomes so bloated that it invalidates the added-val= ue > of the functionality. > > I truly can't understand how Generics is the most requested PHP feature s= o > I will just assume I will have to live with it one day, but mixing it wit= h > Attributes Syntax seems to be a recipe to make it as bad (or worse) than > the experience of using Generics in Typescript. > > > -- > Marco Deleu I also agree with Marco. Generics are a pain in the rear in languages that have them. Usually, the PHP version of the same code written in generic C# or Typescript is much more concise and clear. The only exception to that, would be built-in arrays. If there is exactly one thing that could be "generic", it would be those that. Effectively, a simpler syntax to this: function onlyStrings(string ...$strings): array { return $strings; } onlyStrings(...['array','of','strings']); I'd be thrilled if I could just write: function onlyStrings(array $strings): array { return $strin= gs; } onlyStrings(['array','of','strings']); That is all I want whenever I think of Generics in PHP. The rest is just complicated fluff in my humble opinion. Robert Landers Software Engineer Utrecht NL