Hi all,
After a day and a quite lot of (hot) answers, we can state that making
try/catch braces optional has a weak probability to appear in PHP. But…
This discussion shows a leak of consistency in the PHP syntax regarding
braces. Language constructions (restricted to control structures) such
as: if, else, elseif, while, do/while, for, foreach, see their braces as
optional. And other more “complex” language constructions (that were
introduced some years later) such as: try/catch and switch/case, see
their braces required.
I assume that making braces optional for switch/case is very strange.
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 “proposal” said it is “error-prone”, it will introduce
“bugs that hard to detect”. But… wait, PHP has goto (and who use it?)!
No kidding, PHP allows you to write very nice code quickly. It is
entirely part of the developer to adopt its own coding rules, but PHP
has made choices in the past and it results in an inconsistency
regarding to its syntax. We should take a decision: either make all
braces required but we all know that it is not possible due to backward
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;
± offer a new way to write buggy programs but no more than with other
control structures (think about goto ;-)).
I see more + than - here. Am I wrong?
Moreover, in parallel, a new idea has been landing: introducing the
“rescue” keyword as a shortcut/replacement of try/catch, such as:
$foo = callThatCouldThrow() rescue 'oof';
Is it possible to chain it, such as:
$foo = callThatCouldThrow() rescue anotherCallThatCouldThrow() rescue
'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
about making try/catch braces optional and not criticize PHP syntax…
Best regards :-).
--
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/
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php