# Feedback sought: Optional Braces

**URL:** <https://contributors.scala-lang.org/t/feedback-sought-optional-braces/4702>\
**Category:** Language Design\
**Created:** [December 8, 2020, 1:01pm UTC](https://contributors.scala-lang.org/t/feedback-sought-optional-braces/4702 "2020-12-08T13:01:10Z")\
**Posts on this page:** 1\
**Showing post:** 176

<div class="post-metadata">

**Author:** ![Jasper-M](https://contributors.scala-lang.org/user_avatar/contributors.scala-lang.org/jasper-m/32/1192_2.png) [@Jasper-M](https://contributors.scala-lang.org/u/Jasper-M)\
**Post date:** [December 11, 2020, 9:42am UTC](https://contributors.scala-lang.org/t/feedback-sought-optional-braces/4702/176 "2020-12-11T09:42:35Z")

</div>

Can we circle back to _why_ we actually need special syntax for higher order methods? A lambda argument is _just_ an argument, just like `a`, `"foo"`, `Some(42)`. How do we pass arguments to functions or methods? Between `(` and `)`. Why can’t we simply pass lambda arguments between `(` and `)` like we do with _all_ other arguments? In Scala 2 we have to use `{` `}` for multiline lambda’s because `;` inference between parentheses doesn’t work. My guess is this whole discussion wouldn’t even exist if a different design had been picked in Scala 2, as suggested in this post:

> [@LPTK](#):
>
> I always thought the requirement to switch to curly braces when adding statements was such an annoying and unjustified burden. I don’t see a reason we can’t write this, for instance:
> 
> ```auto
> xs.map(x => val tmp = foo(x); tmp * tmp)
> // or on multiple lines:
> xs.map( x =>
> val tmp = foo(x)
> tmp * tmp
> )
> 
> ```
> 
> This generalizes to multiple arguments, non-lambda arguments, and even partial function syntax:
> 
> ```auto
> foo(0, 1, x => val tmp = foo(x); tmp * tmp, 3)
> 
> foo(val tmp = 42; tmp * tmp, 1, 2, 3)
> 
> foo(case Some(x) => x; case None => 0)
> 
> ```
> 
> It’s natural to treat `;` as higher precedence than `,` because `,` binds to the surrounding parentheses pair, so there is never a visual ambiguity. It might look weird at first, but I think one can get used to it quickly.

The only issue I see is that Scala’s “user-defined control structures” become less native looking. But that seems to be almost inevitable with optional braces. All native syntax now defines the start of the “code block” with different keywords such as `then`, `do`, `with`, `:`. So perhaps if we want to keep native-looking user-defined control structures just pick one of those keywords and roll with it:

```auto
until(foo < bar) do
  println(1)
  println(2)

test("println should print to the console") do
  println(1)
  println(2)

// or

until(foo < bar):
  println(1)
  println(2)

test("println should print to the console"):
  println(1)
  println(2)

```

But in that case I think we should emphasize that the accepted way to pass lambdas and multiline arguments is between regular `(` and `)`, and this is only for usage in DSLs.

Or alternatively don’t pick any code block starting keyword, and let DSL writers get creative with what’s available. E.g. this is already possible:

```auto
scala> object Foo { def update(s: String, f: => Unit) = {println("start"); f; println("end")} }; def test = Foo
// defined object Foo
def test: Foo.type

scala> test("println should print to the console") = 
     | println(1)
     | println(2)
     | 
start
1
2
end

```

\*\*\* As a side note, may I add that using `{` `}` instead of `(` `)` for passing arguments is actually a source of confusion for beginners in scala. I’m 99% sure that virtually all suggestions I have seen here will only worsen the initial confusion.

* * *

> [@japgolly](#):
>
> I guess it’s time to get counter-opinions on the `..` proposal. I’m sorry to say that I hate it, and surprisingly passionately at that. I really dislike the way it looks, not to mention that it’s taking up three chars now instead of one.

I passionately agree.

---

_[View the full topic](https://contributors.scala-lang.org/t/feedback-sought-optional-braces/4702)._
