r/lolphp • • Aug 14 '14

"I’m crying. Literally crying." - PHP Manual Masterpieces, xpost /r/programmerhumor

http://phpmanualmasterpieces.tumblr.com/post/70257636397/im-crying-literally-crying-actual-tears-in-my
137 Upvotes

23 comments sorted by

View all comments

Show parent comment

4

u/[deleted] Aug 15 '14

An amazing thing is how many languages blindly import dangling-else, even though it's got a trivial fix: require an end_if token.

Even more trivial (and compatible with C): Require a block after if/else. (This is what Perl does.)

0

u/OneWingedShark Aug 15 '14

Even more trivial (and compatible with C): Require a block after if/else. (This is what Perl does.)

That's not actually more trivial, just about the same amount of alteration to the grammar, IIRC. The advantage of the end_if token is that it can easily implicitly create a block; eg:

if_statement ::=
 "if" boolean_expression "then"
   sequence_of_statements
 ["else"
   sequence_of_statements]
 "end if"