This page is no longer maintained — Please continue to the home page at www.scala-lang.org

If "} {" is "syntactically confusing"

8 replies
David Hall 4
Joined: 2009-08-21,
User offline. Last seen 42 years 45 weeks ago.

Can we maybe have:

for {
a <- 1 to 1000
b <- 2 to 2000
} do {
println(a * b);
}

Where the do is optional?

I know, I know, even more syntactic sugar, but if the current form
offends so many people...

extempore
Joined: 2008-12-17,
User offline. Last seen 35 weeks 3 days ago.
Re: If "} {" is "syntactically confusing"

On Sun, Nov 15, 2009 at 02:18:50PM -0800, David Hall wrote:
> for {
> a <- 1 to 1000
> b <- 2 to 2000
> } do {
> println(a * b);
> }
>
> Where the do is optional?

Announcing paulp's ForDoSugar Library version 1.0!

object ForDoSugar { def Do[T](f: => T) = f }

> I know, I know, even more syntactic sugar, but if the current form
> offends so many people...

Heading into artificial sweetener territory now. Abort!

http://pbfcomics.com/?cid=PBF116-Sweet_Deal.jpg

David Hall 4
Joined: 2009-08-21,
User offline. Last seen 42 years 45 weeks ago.
Re: If "} {" is "syntactically confusing"

On Sun, Nov 15, 2009 at 2:47 PM, Paul Phillips wrote:
> On Sun, Nov 15, 2009 at 02:18:50PM -0800, David Hall wrote:
>> for {
>>   a <- 1 to 1000
>>   b <- 2 to 2000
>> } do {
>>   println(a * b);
>> }
>>
>> Where the do is optional?
>
> Announcing paulp's ForDoSugar Library version 1.0!
>
> object ForDoSugar { def Do[T](f: => T) = f }
>
>> I know, I know, even more syntactic sugar, but if the current form
>> offends so many people...
>
> Heading into artificial sweetener territory now.  Abort!
>
>  http://pbfcomics.com/?cid=PBF116-Sweet_Deal.jpg

:-)

I'm well aware of pimping patterns. My concern was that there seems to
be a sudden and rapid movement to standardize on banning curly-braced
for loops based on the perception that they're "syntactically
confusing." If the perceived confusion can be undone with a simple
change, I thought it would be worth bringing up.

Jorge Ortiz
Joined: 2008-12-16,
User offline. Last seen 29 weeks 4 days ago.
Re: If "} {" is "syntactically confusing"


On Sun, Nov 15, 2009 at 7:05 PM, David Hall <dlwh [at] cs [dot] berkeley [dot] edu> wrote:
On Sun, Nov 15, 2009 at 2:47 PM, Paul Phillips <paulp [at] improving [dot] org> wrote:
> On Sun, Nov 15, 2009 at 02:18:50PM -0800, David Hall wrote:
>> for {
>>   a <- 1 to 1000
>>   b <- 2 to 2000
>> } do {
>>   println(a * b);
>> }
>>
>> Where the do is optional?
>
> Announcing paulp's ForDoSugar Library version 1.0!
>
> object ForDoSugar { def Do[T](f: => T) = f }
>
>> I know, I know, even more syntactic sugar, but if the current form
>> offends so many people...
>
> Heading into artificial sweetener territory now.  Abort!
>
>  http://pbfcomics.com/?cid=PBF116-Sweet_Deal.jpg

:-)

I'm well aware of pimping patterns. My concern was that there seems to
be a sudden and rapid movement to standardize on banning curly-braced
for loops based on the perception that they're "syntactically
confusing." If the perceived confusion can be undone with a simple
change, I thought it would be worth bringing up.

Who? What? Where? Banning curly-braced for-loops?! Heathens! Is this in the style thread?? I need to find some time to go in there and lay some smack down...

--j

Randall R Schulz
Joined: 2008-12-16,
User offline. Last seen 1 year 29 weeks ago.
Re: If "} {" is "syntactically confusing"

On Sunday November 15 2009, David Hall wrote:
> On Sun, Nov 15, 2009 at 2:47 PM, Paul Phillips wrote:
> > ...
>
> I'm well aware of pimping patterns. My concern was that there seems
> to be a sudden and rapid movement to standardize on banning
> curly-braced for loops based on the perception that they're
> "syntactically confusing." If the perceived confusion can be undone
> with a simple change, I thought it would be worth bringing up.
>

David Hall 4
Joined: 2009-08-21,
User offline. Last seen 42 years 45 weeks ago.
Re: If "} {" is "syntactically confusing"

On Sun, Nov 15, 2009 at 8:08 PM, Jorge Ortiz wrote:
>
>
> On Sun, Nov 15, 2009 at 7:05 PM, David Hall wrote:
>>
>> On Sun, Nov 15, 2009 at 2:47 PM, Paul Phillips
>> wrote:
>> > On Sun, Nov 15, 2009 at 02:18:50PM -0800, David Hall wrote:
>> >> for {
>> >>   a <- 1 to 1000
>> >>   b <- 2 to 2000
>> >> } do {
>> >>   println(a * b);
>> >> }
>> >>
>> >> Where the do is optional?
>> >
>> > Announcing paulp's ForDoSugar Library version 1.0!
>> >
>> > object ForDoSugar { def Do[T](f: => T) = f }
>> >
>> >> I know, I know, even more syntactic sugar, but if the current form
>> >> offends so many people...
>> >
>> > Heading into artificial sweetener territory now.  Abort!
>> >
>> >  http://pbfcomics.com/?cid=PBF116-Sweet_Deal.jpg
>>
>> :-)
>>
>> I'm well aware of pimping patterns. My concern was that there seems to
>> be a sudden and rapid movement to standardize on banning curly-braced
>> for loops based on the perception that they're "syntactically
>> confusing." If the perceived confusion can be undone with a simple
>> change, I thought it would be worth bringing up.
>
> Who? What? Where? Banning curly-braced for-loops?! Heathens! Is this in the
> style thread?? I need to find some time to go in there and lay some smack
> down...

Yup.

http://davetron5000.github.com/scala-style/#comprehensions

The exceptions to this rule are for-comprehensions which lack a yield
clause. In such cases, the construct is actually a loop rather than a
functional comprehension and it is usually more readable to string the
generators together between parentheses rather than using the
syntactically-confusing } { construct:

// wrong!
for {
x <- board.rows
y <- board.files
} {
printf("(%d, %d)", x, y)
}

// right!
for (x <- board.rows; y <- board.files) {
printf("(%d, %d)", x, y)
}

>
> --j
>

David Hall 4
Joined: 2009-08-21,
User offline. Last seen 42 years 45 weeks ago.
Re: If "} {" is "syntactically confusing"

On Sun, Nov 15, 2009 at 8:15 PM, Randall R Schulz wrote:
> On Sunday November 15 2009, David Hall wrote:
>> On Sun, Nov 15, 2009 at 2:47 PM, Paul Phillips wrote:
>> > ...
>>
>> I'm well aware of pimping patterns. My concern was that there seems
>> to be a sudden and rapid movement to standardize on banning
>> curly-braced for loops based on the perception that they're
>> "syntactically confusing." If the perceived confusion can be undone
>> with a simple change, I thought it would be worth bringing up.
>>

Joshua.Suereth
Joined: 2008-09-02,
User offline. Last seen 32 weeks 5 days ago.
Re: If "} {" is "syntactically confusing"
Yes, this syntax is too useful to drop for "style".

On Sun, Nov 15, 2009 at 11:14 PM, David Hall <dlwh [at] cs [dot] berkeley [dot] edu> wrote:
On Sun, Nov 15, 2009 at 8:08 PM, Jorge Ortiz <jorge [dot] ortiz [at] gmail [dot] com> wrote:
>
>
> On Sun, Nov 15, 2009 at 7:05 PM, David Hall <dlwh [at] cs [dot] berkeley [dot] edu> wrote:
>>
>> On Sun, Nov 15, 2009 at 2:47 PM, Paul Phillips <paulp [at] improving [dot] org>
>> wrote:
>> > On Sun, Nov 15, 2009 at 02:18:50PM -0800, David Hall wrote:
>> >> for {
>> >>   a <- 1 to 1000
>> >>   b <- 2 to 2000
>> >> } do {
>> >>   println(a * b);
>> >> }
>> >>
>> >> Where the do is optional?
>> >
>> > Announcing paulp's ForDoSugar Library version 1.0!
>> >
>> > object ForDoSugar { def Do[T](f: => T) = f }
>> >
>> >> I know, I know, even more syntactic sugar, but if the current form
>> >> offends so many people...
>> >
>> > Heading into artificial sweetener territory now.  Abort!
>> >
>> >  http://pbfcomics.com/?cid=PBF116-Sweet_Deal.jpg
>>
>> :-)
>>
>> I'm well aware of pimping patterns. My concern was that there seems to
>> be a sudden and rapid movement to standardize on banning curly-braced
>> for loops based on the perception that they're "syntactically
>> confusing." If the perceived confusion can be undone with a simple
>> change, I thought it would be worth bringing up.
>
> Who? What? Where? Banning curly-braced for-loops?! Heathens! Is this in the
> style thread?? I need to find some time to go in there and lay some smack
> down...

Yup.

http://davetron5000.github.com/scala-style/#comprehensions

The exceptions to this rule are for-comprehensions which lack a yield
clause. In such cases, the construct is actually a loop rather than a
functional comprehension and it is usually more readable to string the
generators together between parentheses rather than using the
syntactically-confusing } { construct:

// wrong!
for {
 x <- board.rows
 y <- board.files
} {
 printf("(%d, %d)", x, y)
}

// right!
for (x <- board.rows; y <- board.files) {
 printf("(%d, %d)", x, y)
}




>
> --j
>
>> -- David
>>
>> >
>> > --
>> > Paul Phillips      | These are the climbs that apply men's soles.
>> > Apatheist          |
>> > Empiricist         |
>> > all hip pupils!    |----------* http://www.improving.org/paulp/
>> > *----------
>> >
>
>

odersky
Joined: 2008-07-29,
User offline. Last seen 45 weeks 6 days ago.
Re: If "} {" is "syntactically confusing"

On Mon, Nov 16, 2009 at 2:20 PM, Josh Suereth wrote:
> Yes, this syntax is too useful to drop for "style".
>
But in the end, how important are for-loops? (I mean, the non-yield variant).
Also, if we allow do after for, the next change request will be to
allow it after while as well, and if we follow that Scala will become
a language that can't decide whether it wants Pascal or C style
syntax.

Cheers

Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland