[fpc-devel] Semicolon before else

Juha Manninen juha.manninen at phnet.fi
Fri Jan 29 08:52:59 CET 2010


>   if x < 2 then
>     if x > 0 then
>       Writeln('x=1');
>     else
>       Writeln('x=0');

I was going to write that's not backward compatible, but it doesn't actually 
compile with current FPC. I remembered now ELSE would be tied to the first IF. 
Anyway, there are some weird cases when it's difficult to tell which IF the 
ELSE belongs to. Those are very rare and then one really should use BEGIN END 
blocks anyway.

So, if this change is backward compatible then it should absolutely be 
accepted in FPC.

For Graeme and others: the problem is not the amount of typing. The problem is 
that you can easily forget this semicolon when you for example add ELSE to an 
existing IF. First there had to be a semicolon and then there must not be 
semicolon... Non-intuitive.
So, the goal is to make the language more intuitive and programmer-friendly.

The compiler can deal with complicated things. It could easily understand the 
semicolon (as we can see with this patch). Instead giving an error feels 
stupid. It is like with the "const array" syntax. The compiler essentially 
says:
"Hey you stupid programmer, you left a semicolon there. I easily understand 
what your code means but still you must change it yourself."

Ok, it is a small thing but still, this language is otherwise clean and 
intuitive.
Using BEGIN END blocks always solves the problem but they are not used always.


Regards,
Juha Manninen



More information about the fpc-devel mailing list