why ; ?

Leandro Lucarella llucax at gmail.com
Wed May 7 08:41:08 PDT 2008


Janice Caron, el  7 de mayo a las 05:22 me escribiste:
> On 07/05/2008, Daniel Giddings <daniel.giddings at gmail.com> wrote:
> > while you might need a \ line break char for some code, it is
> > very much the exception to the rule
> 
> Not if you are obliged (against your will) to write maximum-80-column
> code, it isn't. In that circumstance, wrapping lines is very, very
> common.

Only if you make a lot of steps in the same line or use incredibly long
variables or have a very deep nesting of blocks. Avoiding that usually
improves code readability and maintainability.

> You are also forgetting that any statement block { ... } is
> effectively a single statement, and that, if (...) { ... } else { ...
> } is also a single statement. And within any statement, passing a
> delegate literal to a function - e.g foo(delegate int(int x){ ... });
> is still a single expression. In fact the whole concept of what is or
> is not a "single statement" is really quite nebulous.

*This* is the real problem with making ';' and '{}' optional and why I
stop suggesting this change myself =)

I think Python syntax is way much more elegant and readable than C-like
syntax, but D has some constructions that are very dependant on '{}' and
';'.

Even so, making them *optional* it's maybe possible. You can mark blocks
with indentation *or* '{}', let's say:

void main()
	auto x = some_func((int i) { return i + 5 }) // {} are mandatory for delegates
	while (x)
		x = 0
		{ auto x = 1; writefln("this is a new block") }

A statement is parsed until ';' *or* EOL, a block is defined either by
deeper indentation *or* '{}'. Some constructs have mandatory block
delimitation using '{}'. This syntax should not be hard to parse,
you can give meaningfull errors, and you get backward compatibility.

Everybody should be happy, except from Walter, who has to touch the
parser =)

-- 
Leandro Lucarella (luca) | Blog colectivo: http://www.mazziblog.com.ar/blog/
----------------------------------------------------------------------------
GPG Key: 5F5A8D05 (F8CD F9A7 BF00 5431 4145  104C 949E BFB6 5F5A 8D05)
----------------------------------------------------------------------------
Cada movimiento que no se hace, es un movimiento que se pierde.
Y cada movimiento que se pierde, se transforma en una mochila.
Y las mochilas nos alejan, de nuestros amigos y nuestras amigas.
Y nuestros amigos se transforman, en enemigos y en enemigas.
Cada movimiento que se hace, es una mochila que se deja.



More information about the Digitalmars-d mailing list