logo       

Re: Brace style bias?: msg#00527

lang.scala

Subject: Re: Brace style bias?



Miles Sabin wrote:
>
> I've just been bitten by an interaction between Scala's newline rules
> and my prefered brace style (BSD/Allman style[1]
> ...
> [1] http://en.wikipedia.org/wiki/Indent_style
>

Given a choice, I also use the BSD/Allman style. Here's a concrete proposal
that I believe would make the compiler brace-placement-neutral.


Add "and is not a '{'" to the Scala Language Specification section 1.2, to
give:-

A newline in a Scala source text is treated as the special NewLine
token if the three following criteria are satisfied:
1. The token immediately preceding the newline can terminate a statement.
2. The token immediately following the newline can begin a statement and is
not a '{'.
3. The token appears in a region where multiple statements are allowed.


Add the following example to a tutorial or an FAQ:-

When using braces for scoping, a ';' is needed to terminate the preceding
statement:-

class C
{
{
val x = 1
f(x)
}

def f(n: Int) = Console.println(n)

val x = 2
f(x);

{
val x = 3
f(x)
};

{
val x = 4
f(x)
}
}

--
View this message in context:
http://www.nabble.com/Brace-style-bias--tf3129013.html#a8728125
Sent from the Scala mailing list archive at Nabble.com.




<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise