Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:121396 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 60748 invoked from network); 18 Oct 2023 13:47:05 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 18 Oct 2023 13:47:05 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 4AAC81804BC for ; Wed, 18 Oct 2023 06:47:03 -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,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=3.4.2 X-Spam-ASN: AS15169 209.85.128.0/17 X-Spam-Virus: No X-Envelope-From: Received: from mail-vk1-f178.google.com (mail-vk1-f178.google.com [209.85.221.178]) (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 06:47:02 -0700 (PDT) Received: by mail-vk1-f178.google.com with SMTP id 71dfb90a1353d-49ab3f5863fso411964e0c.1 for ; Wed, 18 Oct 2023 06:47:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1697636822; x=1698241622; darn=lists.php.net; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=Fco5JVYnZrK3xChHTbQJAj0JmOCskn6JM8fkbHbKuBs=; b=bzt24EtJPqBnX+RQyBl6RsxvBczFje2mYf2qmKIfFjdpGRBm9d63tyZYEI8HajpM/n J2WA1bYg07cTVezfuh/DmxRDyztYPfV6nDJhEcjRVj8SO7SBL1nkIiIqnIazDgtTJLLU gSFcX1ue2o/Ob0VzRrs7X1W+0I7+hUpyx55GyVpZPnVXf3zRuIHm2koGUS5qck46593M SAworyYpB2K7zsIsxE32/ykU8vOfT63ELtsLxEEV13AhHi1vkQtb7X9v/d7DMc0UR38y fnJZSgKmg2D0c60QrnQTb1Gv7toBcqCk9TgNKv9i6cW9DDLGMtKAyKv9+cj/XzQXcbaV j3/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697636822; x=1698241622; h=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=Fco5JVYnZrK3xChHTbQJAj0JmOCskn6JM8fkbHbKuBs=; b=V3ykD+5yPCWxCd80tlELKbHZMJh7pd8rFtGmu7wgsE7gCx05m93+ERgky4lArkG7QF Fhx0EsyDzsD9qQ8h/nllxCdi/ArJF6fAEO2JLqLEVZppgcoYfIVYfT6GoOOsy3SGyGkX FiWCE//fKPTf9PqxcqjETAJZH/Owgk9lF+iDDkvwxHUsNV0elgptMPVCrPfbD9CVDSOz 0rLRcZsxayK/MaBB3iBCADDlFcy5gEDQBxIhZQjq6kcUG2Q357XOO9xAaie9TBEDbgap fk1u70kigcqZo41DJzKX5REHGMZignwp4/Bg93f4uXLpreQqHtl5Nwen22Xac/zXR1NQ BJOg== X-Gm-Message-State: AOJu0YxJJabtaDhO4Ee7xCR3ybhbimnCetLalrY5hFA/9XvC3NTqqaGE k255pY4jLBbf5OATY/mKctYjkcIy5wFUFEytrT4= X-Google-Smtp-Source: AGHT+IHtIzKedRew5g2Vgdrqcf4AVVqeUVKagCmMvfOqu7FpIaqqHat5Rq+3GSB+2M+0X6YATjt3Xos9yZMAFMfxyt4= X-Received: by 2002:a05:6102:21c7:b0:457:cccf:75f0 with SMTP id r7-20020a05610221c700b00457cccf75f0mr3911090vsg.2.1697636821839; Wed, 18 Oct 2023 06:47:01 -0700 (PDT) MIME-Version: 1.0 References: <9d5388fa-a5a5-4fa5-81ff-16f6670f80b6@gmail.com> In-Reply-To: Date: Wed, 18 Oct 2023 10:46:25 -0300 Message-ID: To: =?UTF-8?Q?Olle_H=C3=A4rstedt?= Cc: Rowan Tommins , internals@lists.php.net Content-Type: multipart/alternative; boundary="000000000000b935db0607fddfa6" Subject: Re: [PHP-DEV] Previous discussions about generics syntax only? From: deleugyn@gmail.com (Deleu) --000000000000b935db0607fddfa6 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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 the > >> 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 tru= e > > (existing run-time checks) and type information that is "advisory only" > > (new checks for optional static analysis) means users can no longer hav= e > > confidence in that type information. > > > > This is one of the interesting things about the compromise over scalar > > types - if you see a declaration "function foo(int $bar) { ... }", you > > *know* that $bar will be an int at the start of every invocation of tha= t > > function, regardless of which mode the calling code uses. I think addin= g > > exceptions to that certainty would be a bad direction for the language. > > > > On the other hand, I can see a "third way": if the problem with current > > 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 reflection > > 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 somethin= g > > 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 fro= m > > reflection and receive an AST representing the type constraint int|floa= t > > } > > 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 stuff, Typescript verbosity becomes so bloated that it invalidates the added-value of the functionality. I truly can't understand how Generics is the most requested PHP feature so I will just assume I will have to live with it one day, but mixing it with Attributes Syntax seems to be a recipe to make it as bad (or worse) than the experience of using Generics in Typescript. --=20 Marco Deleu --000000000000b935db0607fddfa6--