Submitted by marian (Sun Apr 03 21:03:18 UTC 2005)
if ... then if ... then ... end | end | <--- 3 lines to indicate end of code blockend |
if 5 > 4: if 5 > 2: <--- indentation is compulsory puts "hello"
The other syntax is still compatible: def f()
if 5 > 4 if 5 > 2 puts "hello" <--- indentation is optional end endend
In the future the "end of block" syntax may get deprecated and replaced by indented blocks.
Languages like Python and Haskell (see the 'do' syntax) use indented blocks to avoid this. For the above example: if ... :
if .... : if ... : ...
In this example ':' means "beginning of indented block" We don't have to write the three ends as they are put automatically by the lexer. As a restriction, each of the inner blocks have to be indented. The same may be applied to any definition (class, modules, methods): class c:
Most of the current programs may remain untouched since it is not common to use ':'. Compatibility is assured.
In the future the "end of block" syntax may get deprecated and replaced by indented blocks and we may be able to write: if 5 > 4 <-- the ':' is no more required
RCRchive copyright © David Alan Black, 2003-2005.
Powered by .
We don't need one of Python's worst features.
As you can see, many Rubyists are not Pythonists for this very reason. A strange world :-)
A python feature that I dearly miss in ruby.
Compatibility is not 100% - this breaks:
if foo: bar end