Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:128057 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 lists.php.net (Postfix) with ESMTPS id 778DC1A00BC for ; Tue, 15 Jul 2025 17:40:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1752601120; bh=dX3JXGiSWe+fTJfP9TubbPeMcqtETy+OsR4yjlnc7GM=; h=From:Subject:In-Reply-To:Date:Cc:References:To:From; b=n9Nf9h4DRzAjNCd7nndfDvdI1YgquuokKB1BeEfXV2UM4lZtURB4NeVxaf+xezT7k 42G49pvu7uUYSkDw2pX3b1B/vAwRBjbNha7tY5jkp3PJ4V1tbA+AxqOiPszmZm2zc4 BRJEX4XKYrFPpMX3tKmdfsRpTdJq0bq2kjm2UFj8zjv7Fp/2O0l3rF1qD0JsWJKows 9/Lc2ZAbsXuASbcij9rqUv5X6lROqvohlg6DII8n98DHU0Kq3M+ezIosdiRPHXUxi7 G35N9qyYVb44/vISTJaltfjNzjwfVjBw6lkIPhOw1NTHYigUrtNSQsf+0f3mrJeFvT UpQCcCTchXyWA== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id C1E121805B0 for ; Tue, 15 Jul 2025 17:38:39 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-0.4 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=4.0.1 X-Spam-Virus: Error (Cannot connect to unix socket '/var/run/clamav/clamd.ctl': connect: Connection refused) X-Envelope-From: Received: from mail-lf1-f51.google.com (mail-lf1-f51.google.com [209.85.167.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 ; Tue, 15 Jul 2025 17:38:39 +0000 (UTC) Received: by mail-lf1-f51.google.com with SMTP id 2adb3069b0e04-553ba7f11cbso5773115e87.1 for ; Tue, 15 Jul 2025 10:40:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1752601226; x=1753206026; darn=lists.php.net; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:subject:mime-version:from:from:to:cc:subject:date :message-id:reply-to; bh=s90SriAPDqPtPOawJDbQWHSX4eAJkwVSiIYUJNGO0L4=; b=nsWBe/YzWQqECeoxf93AG+6g89eOh6D2uQpwFmcuNoWx57OqL8RGAsfXCKgMRqxquu 4Fvw8dc4m6/hKsK6bAWYY90VuLAsXMP72mLmZDdW/GtC6IAXlOV19MDMAEcaRnWx4XBo wWKVr3Y1L7Hvvo3sl1/P/NyOUzGbXcg1Q2vWoaEiynPbdP/w7aoVy8Zljaxkzx9Y8YSM 7E9C7pbxpOG6cD2CSbUBNFISMQM3M/Xg51V2mGelVpmIyLxlSbm6lyWmDoeDVkQ9oixF FQu3fEAR7TjBpDjpLwrnEVXZ5cZzXVPqMIwATsMNeo3pWKpjddBFlqGR/hFX2d1XBuIq QTgg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752601226; x=1753206026; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:subject:mime-version:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=s90SriAPDqPtPOawJDbQWHSX4eAJkwVSiIYUJNGO0L4=; b=BWhvwDRuXcsNAw2pMpQy2/Tl8/CoasKvbIGShhotRUhtxEpQtyW5Uw6XL0zsiRt8bW lcdsJMBZygDn3r2V+T1RdibRHhTTHNjdLp+y/ZMZPpkgblkUMZ5m2KuJc3lZh+bQ+viW XXkPnB69/SHIXvdR9b5bxZ3aeIHAdUyoY95GU02RD30vHiilyyCYtK72CMx2TpfVCEyx f7q7b0VXxno9MnqrnYwlSWwjoOFB0ECNvqcqV/04vNWO9cnVp9qWMe84GDwMSfjKPnB4 eMUhJUWhUbpLvehs4DIq3AGVp7Gkbby+lrW8u5+pyVIzmWuqvAiqB5X1Ze5QyJjN5NwI fUVw== X-Gm-Message-State: AOJu0YwP6CN2V50dqLzX2QOXZLfvfu2GfHtsKWNIakN4hr4NwHSJAYJy v1oD6q91aP0fmDoDPE+YQd880NLBecqD74cYUFhBmdwKdy3am2kAXOSk X-Gm-Gg: ASbGncvdz0T3VhWFHTFPcvfjxAycqC5dsFbPqIJ45i6uZ6VI4ZmDwnUUB4lkzyRBWVx /8E87fyFxciR/kCA3mY2nJNL8K0enEh9f+4OSEhPGNzrN5Qy/n2EzAKs8824vZR1fWW5w+eLYMc wiSuYeck8abEYxVr5nX0yUatAYGTmH0wMYZJG9ibc0PSpj64IJxz7pZUYwPi4vIwFvK5D9X8yLS tF9CnAluFUQhMmInKA1750JM+g6Iuyp4hVkS7gGTN9LqAcAwyK0EstrfvEAb0tpoW25McdV4oAy UA8dMbKik/iQUDbC+twzSHGxdeD0DFSPxnMZjCLkESOenuKUH2eEzR4xAmfRqnQ50jmsIJkdWn5 HIT0PB/7tVxH02XeICI6nyokii9vgbyn0 X-Google-Smtp-Source: AGHT+IGNXoFK1OnGCuIfzSMw5bPbuH30enXIKdic94baa+4uvEyRh4cDSfKlKZeCJ9H+UD3oCyBoxw== X-Received: by 2002:a05:6512:4004:b0:553:33b9:bd3a with SMTP id 2adb3069b0e04-55a233b3011mr89575e87.53.1752601225284; Tue, 15 Jul 2025 10:40:25 -0700 (PDT) Received: from smtpclient.apple ([46.73.17.85]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-5593c9d0914sm2378536e87.112.2025.07.15.10.40.24 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 15 Jul 2025 10:40:24 -0700 (PDT) X-Google-Original-From: Dmitry Derepko Content-Type: text/plain; charset=utf-8 Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3826.600.51.1.1\)) Subject: Re: [PHP-DEV] RFC: Single-Expression functions In-Reply-To: <68682212b6cc36ebd775e2504d941079@bastelstu.be> Date: Tue, 15 Jul 2025 20:40:13 +0300 Cc: PHP internals Content-Transfer-Encoding: quoted-printable Message-ID: <4BFE8460-591B-4AE1-81FC-9E04D69CA999@gmail.com> References: <68682212b6cc36ebd775e2504d941079@bastelstu.be> To: =?utf-8?Q?Tim_D=C3=BCsterhus?= X-Mailer: Apple Mail (2.3826.600.51.1.1) From: xepozzd@gmail.com (Dmitry Derepko) Hi Tim,=20 Great questions, I=E2=80=99ll try to answer them all.=20 Sorry for the late answer, looked like there are no interest in the RFC = and I almost forgot about it. > On Jun 4, 2025, at 12:23=E2=80=AFPM, Tim D=C3=BCsterhus = wrote: >=20 > In the implementation I'm seeing that `$a =3D function() =3D> 123;` = will also become legal (=E2=80=9Cshort closures with function instead of = fn=E2=80=9D). This is not mentioned in the RFC text. It also raises the = question how that variant will interact with variable capturing. Nope. Anonymous functions won=E2=80=99t become available. Use arrow = functions with auto-capturing instead. RFC propose classic function and class methods become available be = one-liners > An AST printing test in the implementation would be useful to have. = You can do that with `assert(false && new class { });` (using an = anonymous class). Sure, when RFC successfully pass Voting stage, alright? > I believe the reasoning given is not a fair comparison. The RFC says = that `getName() "Name"` would be the relevant information, which I can = agree with. But this is not what the proposed syntax looks like. A fair = comparison would be: >=20 > function getName() { return "Name"; } > function getName() =3D> "Name"; >=20 > And when compared like this, it becomes clear that you are trading = `{}` for `=3D>` and effectively only save the `return`, which to me = provides little incremental value. Especially when comparing the = signatures from the Calculator example: >=20 > public function multiply(int $a, int $b): int =3D> $a * $b; > public function multiply(int $a, int $b): int { return $a * $b; } Cool point. I=E2=80=99ve updated examples. > I also don't like how the actual implementation is pushed to the right = of the line. This makes it harder for me to scan for it. The linebreaks = that the RFC states =E2=80=9Ccreate cognitive overhead=E2=80=9D guide = the eye for me. So perhaps we should also compare: >=20 > public function multiply(int $a, int $b): int > =3D> $a * $b; > public function multiply(int $a, int $b): int { > return $a * $b; > } I don=E2=80=99t think it=E2=80=99s correct comparison. Why the linebreak = should be there? If it is set by an editor, it=E2=80=99s not programmer/language issue. = Set your editor to: - Single expression function becomes regular when the line is greater = than 180 chars AND/OR Vice-versa - Same above, but ignore instead of breaking the line - Other > So basically the only thing we gain is the removal of a keyword in = some situations. When trying to extend the logic in a function to more = than one expression (which is not unlikely for methods), I would be = forced to make multiple =E2=80=9Cboilerplate=E2=80=9D changes instead of = just adding my logic, effectively undoing any benefit the syntax = might've provided. Correct point, almost. Intellij IDEA provides quick action for Kotlin = SEF=E2=80=99s, so you may turn SEF -> Regular and vice-versa calling = CTRL+ENTER, Chose correct option, Enter. Usually, we read code tens times often then write.=20 ---------- Best regards, Dmitrii Derepko. @xepozz