lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Saturday 01 December 2007, Wesley Smith wrote:
> I think because the if statement doesn't need parentheses:
> 
> if p < 8 then p = 9  end
> 
> if no then then how would you interpret this:
> 
> if p < 8 p = 9 end

Easy: The rule that looks for the condition expression just gives up 
when it sees the second "p", as it would need and operator or 
something there in order to continue the expression. So, it 
returns "p < 8" (well, not literally, but you'll know what I mean, if 
you've implemented a parser), and then the "if" rule statement asks 
for a body statement, and gets "p = 9". There!

The general problem with removing things like this is that it can 
sometimes drastically increase the risk of little typos generating 
very weird compile errors, or worse, code that accidentally compiles 
but doesn't do what you intend. Basically, the parser knows less 
about what you *mean*, and thus, tends to give more confusing error 
messages when things go wrong.

Debugging is where most people spend most of their time. Saving a few 
keystrokes on things like this can be a very bad trade-off. Don't get 
me wrong; I strongly dislike overly verbose languages - but reality 
is not all black and white. Good solutions are all about balance.

That said, I use pretty much exactly this suggested syntax in EEL (I 
just use ';' instead of 'end', and '{'/'}' are optional for a single 
statement body), and I haven't managed to shoot my leg off with it. 
Yet. ;-)


//David Olofson - Programmer, Composer, Open Source Advocate

.-------  http://olofson.net - Games, SDL examples  -------.
|        http://zeespace.net - 2.5D rendering engine       |
|       http://audiality.org - Music/audio engine          |
|     http://eel.olofson.net - Real time scripting         |
'--  http://www.reologica.se - Rheology instrumentation  --'