Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:110195 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 34704 invoked from network); 17 May 2020 00:03:06 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 17 May 2020 00:03:06 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 2391A1804C4 for ; Sat, 16 May 2020 15:40:52 -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=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE 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-qk1-f174.google.com (mail-qk1-f174.google.com [209.85.222.174]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Sat, 16 May 2020 15:40:51 -0700 (PDT) Received: by mail-qk1-f174.google.com with SMTP id m11so6551571qka.4 for ; Sat, 16 May 2020 15:40:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=newclarity-net.20150623.gappssmtp.com; s=20150623; h=mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=JG6mSytR0N3r6nXaroMPoU+jd9QFFlq3j3UeC+tkQi0=; b=JjhbYFZc2gztZ+g2TV8Z+diekGFRuHuC1Vi1tgaKJSX3MNBKQnL/vt2U9WhW2o7KNH ml0RqILP3duvwYOoZ8XFTkYXj8/VRV5sFuCIQwz7FTvKQ493fFfk00P7I9HrD+Z6LRbn U9VVAxDWOaV/w90zJt9NA10KY5BLH4wRqUCuwNh9YF+RuPq46QDKvnXoPoD9odYMfsBp FeINCp8EUBkKqJyWHlWEUz/mVRvKKxmey2T1Lo7wdX5XCmZBH47GFs5Bf53rLU14OlnA LrJCBXsECjOYLvTNcAtPT7gzyH8qinpEda4LBJ/2Dwx8J9FkQLjyfndd+2qZIEJOp0OI GEng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=JG6mSytR0N3r6nXaroMPoU+jd9QFFlq3j3UeC+tkQi0=; b=cykj+HATrEm/bVMYscoKwW7Pt5Ia8NKP9ogZ9OID7CiTMUUs6ncY+d8YjnglplK6r9 aq3/T7BIwtwJKSWsA/y08Kzdg04KtgwveSycW1Fb+TByodsdpPWSOJS6QzMMgTvEgMW4 YY+LtKpE5egrVBL5atPli1GbpKKjNqfuk5bU970+KsDB/G0ONOhRckvJJgkPvZMHIYd9 JrBhKDra8K1mdFEQxmW8sfDBkCMHLFdreu9VsuKS84Nbsw/cPlbVOwW/A/7YPUyiTorK Jn+H9Ka57wu+VodwxY8g2YwZhFERWMG0M2wl3FJov/fKJUIbuVsYVKYC6uvekTM/UuIV tNww== X-Gm-Message-State: AOAM530OiDxKoxmKe8rfb7EeaHUr2twfppcPBlKEgjyPEwX6rVGm6/TV PTFyWmZUfiZJ010/KyWS6CAr/A== X-Google-Smtp-Source: ABdhPJyId7T3j8dqq9AeXSRR1aHRS93I3mnUboC9aogOeSLzU/oeWu/DIjCftYCxZNrRnbKQM5QfiQ== X-Received: by 2002:a37:9dc5:: with SMTP id g188mr9290422qke.193.1589668847595; Sat, 16 May 2020 15:40:47 -0700 (PDT) Received: from ?IPv6:2601:c0:c680:5cc0:7dc4:faf5:9164:6cb4? ([2601:c0:c680:5cc0:7dc4:faf5:9164:6cb4]) by smtp.gmail.com with ESMTPSA id g57sm5604006qtb.48.2020.05.16.15.40.46 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sat, 16 May 2020 15:40:46 -0700 (PDT) Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 12.4 \(3445.104.11\)) In-Reply-To: Date: Sat, 16 May 2020 18:40:45 -0400 Cc: internals@lists.php.net Content-Transfer-Encoding: quoted-printable Message-ID: <3576B8C4-D9E7-4C54-9D19-5F3ACDFF76F9@newclarity.net> References: To: Pavel Patapau X-Mailer: Apple Mail (2.3445.104.11) Subject: Re: [PHP-DEV] [RFC] Guard statement From: mike@newclarity.net (Mike Schinkel) > On May 16, 2020, at 5:13 AM, Pavel Patapau = wrote: >=20 > Hello everyone, >=20 > I want to propose new syntax addition - guard statement, that executes = code only if expression equals false and must contain control-flow = changing code, and written a respective RFC: >=20 > https://wiki.php.net/rfc/guard_statement > >=20 > Implementation in progress. >=20 > I started work before this proposal = https://externals.io/message/110107 and respected some moments in the = RFC. >=20 >=20 > Thanks for consideration, > Pavel Many others have already made comments that I agree with so won't echo = as they have already been said. Two points: 1. That adding a `guard` would make it a reserved word is of significant = concern to me, and looking at your examples I would ask why not simply = ask that the if statement be able to omit the "true" block which could = accomplish the same w/o needing to add another reserved word? e.g. if (condition) else { //this code executed only if condition equals false return|throw|goto; //or continue | break(in loop context only); } // in loop context - valid code while (condition){ if (condition) else { break; //valid } } Alternately, why not simply use what we already have, and what I do = often, invert the condition? if ( ! condition) { //this code executed only if condition equals false return|throw|goto; //or continue | break(in loop context only); } // in loop context - valid code while (condition){ if ( ! condition ) { break; //valid } } Secondly, you reference this essay[1] which mentions why multiple = returns are a bad idea, yet your proposal seems to want to encourage = people to write more early returns, not fewer. Regarding the multiple returns, consider the following, using an = if(condition)else{} syntax AND assuming that we could add support for = try{} without being required to use a catch(): function example() { try { $value =3D null; if (condition1) else { break; } if (condition2) else { break; } if (condition3) else { break; } $value =3D do_work(); } return $value; } -Mike [1] = https://medium.com/@scadge/if-statements-design-guard-clauses-might-be-all= -you-need-67219a1a981a=