Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:126062 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 017931A00BD for ; Tue, 26 Nov 2024 17:45:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1732642924; bh=xb8IavQ+5/4+PQhEFqXKm6g23PAoeGfevVpzP//UXV0=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=NOUMq+56oSY7eflXqCHv/PQ8GeR6h+QQcWX1/LRJOj6UVHppU83KZ9uVbYWVZLCGp AjwolgRpcxlmxafc3t9RKw0pGf+ZlW4uK+3mZ41DfOYFDYkhUcCRE5ABIbn9UcFHDw IeL32juYVBtHuR3oKL/QBCe1yEdp3A9/5bc0Y2aX+l7m6kn3ZE/SfcKiSEli103MA4 TvyA9J1Dsk/CryyRHSwVTFuQCWaZuBAiIPX3tmdvlPm+qdt1U3FbPcW/b4CrM2N/SY g+KIHPksNDkktvQ5YtZJDT2xr3+auHW4VslAmoXMklXtZGP0RXqkdL8jTVTfgCJhVx KcvPiROfPlzyw== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 2005C18004D for ; Tue, 26 Nov 2024 17:42:02 +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,FREEMAIL_FROM, HTML_MESSAGE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from mail-ej1-f42.google.com (mail-ej1-f42.google.com [209.85.218.42]) (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, 26 Nov 2024 17:41:58 +0000 (UTC) Received: by mail-ej1-f42.google.com with SMTP id a640c23a62f3a-aa5302a0901so463333366b.0 for ; Tue, 26 Nov 2024 09:45:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1732643107; x=1733247907; 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=hk8ed4/ST4iA5VpfNsOLfQA/VSt1uoxDL7tbNcf7fp0=; b=Ubn3sndxCVrhu+y/XpW8PJX+xKHEZjMV7HNpG7D6zV8uVEVX6PQfnkDbxCOOoByVtE 1JkAfZPmz5obr0ceFwXElVeOTE31z9Yh6ra+DJyIGIeGH8UQCiao/LPMTL7Q2Ecr5PVC ig3faEWVzKY400qybh4gIDS2i3OOkMTzv06ZdMpV2WVpIuYxFD524qXW64SBbNlO+Uj5 zr+bfs8Lc3EHnDZ+T4Zryq7ntwDHAAOwq57reG8MQnupz+Br6GCwkGNsfak1ey+TpZ3d MAFjCt8BZ+Rmlnlq7VRK8OCjp4xwI94YPOpvPhpOPlDdu71KPIX990QGf5BEHLB7ujzL 46cQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732643108; x=1733247908; 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=hk8ed4/ST4iA5VpfNsOLfQA/VSt1uoxDL7tbNcf7fp0=; b=agrjGJ62LtkAWh1MNWosWeaSBJrcU9U8tbCvlBOP+1dVb+OURrDc4BXYRQvxar8Wf6 aCcaD/DWdfBFUZsdBq0209tA/JIUv37k16iYzAmFDge4hUdqAaBnz53xmg4/karQhRcA 7WK/RP161WJGqz6pq023tglRbAp2jO06yCPSwp+UVpbHUg8TBlxGZR4HeCxjQEpwoGhv KHi6Gnq+x9waTmfBmgYb2lhdrptWICYp65xEl0xgy3k1hoZbVDRzrLI3LVGV+mXUTtAa YO5r+wt50eFCIoqZ5Jl7FqqSSXWDKdft1797vvI+8+XLAnQUNNI1VPxsSbltxceOWtbU sc8w== X-Forwarded-Encrypted: i=1; AJvYcCUO0frPtjf8K2BcKgpU/UOmy/7ydPj24Zq+uE4LvfgWLuIsXXRB+1ntni5nC3Em3jEwOTz4UMgx6Tc=@lists.php.net X-Gm-Message-State: AOJu0YxEVMlWZJYFi1VIDQQi8sx3LbG6x+5oon5z1DwYLbULvpRuHjpM EXg2Vvl3FGZQX4vWiJouhG3xGNdGFpZcwB1Ym+fPA9gs8ha4knc0r0cUj3HArk5TUytzzYoyyVd 0unSxlQnJEsgxfb4nffDAnUsY9sU= X-Gm-Gg: ASbGncsOtNcwI7ETxpM6J/587ntJQoj7JHAmwxV3xl+0R6wAKFL9RaIg2Ze2KgmtVM5 kFblotl7bkCtRf7upAsrCfeR4tEEag2u/YFOxGMLpK4EczFef/w7os1+v+wZ5Hg== X-Google-Smtp-Source: AGHT+IH2DUE1kQnUtGrtNbehddKiGUpG/YhO2aJB7tKcYjGew8VKqP0vlqke4yNmC1BxiiF8o76ncaqyZ+iKN99Ln+E= X-Received: by 2002:a17:906:2181:b0:aa5:42aa:134e with SMTP id a640c23a62f3a-aa542aa709emr867185566b.30.1732643107327; Tue, 26 Nov 2024 09:45:07 -0800 (PST) Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 References: <99f8520a-e8ba-471c-bcdb-6f305089c66b@gmx.de> In-Reply-To: <99f8520a-e8ba-471c-bcdb-6f305089c66b@gmx.de> Date: Tue, 26 Nov 2024 18:44:41 +0100 Message-ID: Subject: Re: [PHP-DEV] Return When To: "Christoph M. Becker" Cc: Volodymyr Volynets , internals@lists.php.net Content-Type: multipart/alternative; boundary="000000000000ef59870627d4685a" From: kjarli@gmail.com (Lynn) --000000000000ef59870627d4685a Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Tue, Nov 26, 2024 at 6:18=E2=80=AFPM Christoph M. Becker wrote: > On 26.11.2024 at 17:10, Volodymyr Volynets wrote: > > > I have an idea which will save a lot of code. I am proposing to add": > > > > return when [condition], [return value]; > > > > This construct will remove a lot of ifs statements after method calls. > For > > example: > > > > $result =3D Class->method(); > > if (!$result['success']) { > > return $result; > > } > > > > This becomes: > > return when !$result['success'], $result; > > > > Any thoughts? > > What's wrong with > > if (!$result['success']) return $result; > > That's not longer than what you are proposing, and in my opinion, quite > readable. > > The fact that contemporary coding standards require you to write the > if-body on a separate line and to always use braces, is perhaps a > problem of these coding standards. > > Christoph > I don't know if PHP needs this feature, though for me this notation is harder to quickly scan and see what it does. It's really relatively easy to find out what a line of code does when it starts with if, for, foreach, while, do, switch, return etc, The example you've provided reads to me as an if and then the part below is the body of the if. To find out it's a return I first have to look to the right of what was written. I used to write `if something then return end` in Lua, but the more I had to read back my code I started disliking the readability of this formatting. --000000000000ef59870627d4685a Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable


=
On Tue, Nov 26, 2024 at 6:18=E2=80=AF= PM Christoph M. Becker <cmbecker69@= gmx.de> wrote:
On 26.11.2024 at 17:10, Volodymyr Volynets wrote:

> I have an idea which will save a lot of code. I am proposing to add&qu= ot;:
>
> return when [condition], [return value];
>
> This construct will remove a lot of ifs statements after method calls.= For
> example:
>
> $result =3D Class->method();
> if (!$result['success']) {
>=C2=A0 =C2=A0 =C2=A0return $result;
> }
>
> This becomes:
> return when !$result['success'], $result;
>
> Any thoughts?

What's wrong with

if (!$result['success']) return $result;

That's not longer than what you are proposing, and in my opinion, quite=
readable.

The fact that contemporary coding standards require you to write the
if-body on a separate line and to always use braces, is perhaps a
problem of these coding standards.

Christoph

I don't know if PHP needs= this feature, though for me this notation is harder to quickly scan and se= e what it does. It's really relatively easy to find out what a line of = code does when it starts with if, for, foreach, while, do, switch, return e= tc, The example you've provided reads to me as an if and then the part = below is the body of the if. To find out it's a return I first have to = look to the right of what was written. I used to write `if something then r= eturn end` in Lua, but the more I had to read back my code I started dislik= ing the readability of this formatting.


=
--000000000000ef59870627d4685a--