Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:61544 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 96527 invoked from network); 20 Jul 2012 08:33:19 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 20 Jul 2012 08:33:19 -0000 Authentication-Results: pb1.pair.com header.from=ivan.enderlin@hoa-project.net; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=ivan.enderlin@hoa-project.net; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain hoa-project.net from 95.130.12.24 cause and error) X-PHP-List-Original-Sender: ivan.enderlin@hoa-project.net X-Host-Fingerprint: 95.130.12.24 host1.trois-doubles.net Linux 2.6 Received: from [95.130.12.24] ([95.130.12.24:51688] helo=host1.trois-doubles.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 97/4A-18983-BC719005 for ; Fri, 20 Jul 2012 04:33:16 -0400 Received: from Hwhost2.local (241-68.77-83.cust.bluewin.ch [83.77.68.241]) by host1.trois-doubles.net (Postfix) with ESMTPA id 1CCBC207C52 for ; Fri, 20 Jul 2012 10:33:12 +0200 (CEST) Message-ID: <500917C7.3050302@hoa-project.net> Date: Fri, 20 Jul 2012 10:33:11 +0200 Reply-To: ivan.enderlin@hoa-project.net User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:15.0) Gecko/20120715 Thunderbird/15.0a2 MIME-Version: 1.0 To: internals@lists.php.net References: <5007D707.2070100@hoa-project.net> <095CAA408DA94AFB9E75C12877A9043D@charliesomerville.com> <36467402DA0F4332A523162E3C278042@gmail.com> In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: quoted-printable Subject: [PHP-DEV] Make try/catch brackets optinal From: ivan.enderlin@hoa-project.net ("Ivan Enderlin @ Hoa") Hi all, After a day and a quite lot of (hot) answers, we can state that making=20 try/catch braces optional has a weak probability to appear in PHP. But=E2= =80=A6 This discussion shows a leak of consistency in the PHP syntax regarding=20 braces. Language constructions (restricted to control structures) such=20 as: if, else, elseif, while, do/while, for, foreach, see their braces as = optional. And other more =E2=80=9Ccomplex=E2=80=9D language constructions= (that were=20 introduced some years later) such as: try/catch and switch/case, see=20 their braces required. I assume that making braces optional for switch/case is very strange.=20 It's really a _block_ of cases. If you have only one case instruction in = your switch, maybe you should rewrite it. But the case (no joke) of try/catch is different. Most of the people who = were against my =E2=80=9Cproposal=E2=80=9D said it is =E2=80=9Cerror-pron= e=E2=80=9D, it will introduce=20 =E2=80=9Cbugs that hard to detect=E2=80=9D. But=E2=80=A6 wait, PHP has go= to (and who use it?)!=20 No kidding, PHP allows you to write very nice code quickly. It is=20 entirely part of the developer to adopt its own coding rules, but PHP=20 has made choices in the past and it results in an inconsistency=20 regarding to its syntax. We should take a decision: either make all=20 braces required but we all know that it is not possible due to backward=20 compatibility, either make all braces optional when it is necessary. Making braces optional for try/catch does: + not break backward compatibility; + add consistency in the PHP syntax; =C2=B1 offer a new way to write buggy programs but no more than with othe= r=20 control structures (think about goto ;-)). I see more + than - here. Am I wrong? Moreover, in parallel, a new idea has been landing: introducing the=20 =E2=80=9Crescue=E2=80=9D keyword as a shortcut/replacement of try/catch, = such as: $foo =3D callThatCouldThrow() rescue 'oof'; Is it possible to chain it, such as: $foo =3D callThatCouldThrow() rescue anotherCallThatCouldThrow() rescue=20 'oof?'; Maybe we should start another topic because it could be a nice idea. Finally, I would like to clarify my proposal: I just wanted to discuss=20 about making try/catch braces optional and not criticize PHP syntax=E2=80= =A6 Best regards :-). --=20 Ivan Enderlin Developer of Hoa http://hoa.42/ or http://hoa-project.net/ PhD. student at DISC/Femto-ST (Vesontio) and INRIA (Cassis) http://disc.univ-fcomte.fr/ and http://www.inria.fr/ Member of HTML and WebApps Working Group of W3C http://w3.org/