On Sun, 28 Jan 2001, Harry Ohlsen wrote:

> >A statement break into mutliple lines if it is not complete,
> >i.e. "if the last token on a line is an operator or comma".
> >But you can also use \ as the last character on the line, to
> >continue on the next line.
> >
> >a = 2 +
> >    3
> >is equivalent to a=2+3
> >
> >a = 2  \
> >    + 3
> >
> >here you need the \ at the end of the line.
> 
> While it's nice that you can do this, can someone explain why it is
> that the Ruby parser can't work out that a statement is not finished,
> as, say, a C++ or Java parser can?

I guess this was already answered in other mails.

> I assume it makes the parsing a little easier, but I do find it a pain
> each time I get a syntax error because of this sort of thing and it
> takes me a while to realise what the problem is.

I wrote to relief your pre-pains a bit.

I agree it's a pain in the ass to get syntax error because of missed
'\'. But it's quite rare event. First, this particular case doesn't
give syntax error (and actually creates even more pain as a side
effect). Then the second reason is that this is a case you just have
to remember. The memory aid is there: the same works in same way in
many other languages too. But you have to remember the "rule" by
yourself. Most people do remember, and thus the overall harmful effect
is sufficiently small.

Anyway, this bug doesn't bite too often by accident. If you adopt
"right" style to write code (include operator or dot as a hint of
continuation to the same line) it's very rare event you need
'\'. During my sufficiently short Ruby career I can't remember using
this notation more than two times.

Usually when a statement grows over line there's something in your
code which uses it's last way of signalling it should be fixed.

   - Aleksi