There’s a table reserved for the keyword then since Scala 2.10, and I am wondering if any party is going to show up.

In other languages

In ALGOL 60 and Pascal if statements are written like this:

if foo < 0 then begin WriteLine('gaa'); end;

Not sure how far the use of then goes back, but we can see the remnant in ML family of languages like SML, OCaml, F#, and Haskell. Here’s F#:

if x < 0 then printfn "neg" else printfn "non-neg"

In Scala

There’s been multiple attempts at introducing Pascal/ML style if expression to Scala.

In 2011, SIP-12 Uncluttering Scala’s syntax for control structures was proposed by Martin.

Introduce a new keyword, then . Allow the following alternative syntax form: if expression then expression [else expression] At some point in the future (there’s no rush) we could deprecate the form if (expression) expression else expression

In August 2016, SIP committee unanimously rejected SIP-12.

(Edit) I originally linked to Consider syntax with significant indentation here, but now I see that if-then had been in already at that point.

The state of then

As it stands, in Scala 2.13.0-M3 REPL no longer warns about then :

scala> val then = 1 then: Int = 1

but it does for compilation:

[warn] /Hello.scala:18: then is a reserved word (since 2.10.0); usage as an identifier is deprecated [warn] object Test { val then = 1 } [warn] ^ [warn] one warning found

(Edit) Dotty implements Pascal/ML style if-then

scala> if 1 > 0 then println("bar") bar scala> if 1 > 0 then { println("foo") } foo

so it takes harder stance on then used as an identifier.

[error] -- [E032] Syntax Error: /Hello.scala:18:18 [error] 18 |object Test { val then = 1 } [error] | ^^^^ [error] | illegal start of simple pattern [error] one error found [error] (compile:compileIncremental) Compilation failed [error] Total time: 3 s, completed Feb 26, 2018 10:56:14 PM

As a former Delphi programmer, I am more than happy to include then into the Scala language. If Dotty’s then is a thing, I would propose to add it to the list of reserved word in Scala Language Spec, and forbid its use as an identifier under -Xsource:2.14 flag.

Otherwise, we should remove both the warning in 2.13 and the error in Dotty. Then. Or then not.