It’s always possible to come up with synthetic examples to make any language feature look arbitrarily bad. That’s a pretty meaningless discussion that will get us nowhere.
Here’s some real-world code I just came across that would benefit from this language feature being proposed:
def pomSettings: PomSettings = PomSettings(
description = artifactName(),
organization = "com.lihaoyi",
url = "https://github.com/com-lihaoyi/scalasql",
licenses = Seq(License.MIT),
versionControl = VersionControl.github(
owner = "com-lihaoyi",
repo = "scalasql"
),
developers = Seq(
Developer(id = "lihaoyi", name = "Li Haoyi", url = "https://github.com/lihaoyi")
)
)
Perfectly idiomatic Scala: immutable case class
es, collections, factory methods, named parameters, explicit type annotations. This is as vanilla Scala as it gets.
But when you look at the code, it’s kind of clunky. licenses = Seq(License...)
, versionControl = VersionControl...
, developers = Seq(Developer(...))
. There’s tons of boilerplate plate and unnecessary duplication, and def pomSettings: PomSettings = PomSettings(...)
is the kind of verbosity that you find in Java that Scala programmers like to feel smug about avoiding. It’s true that Scala is often pretty concise, but in the very common scenario of constructing nested data structures, Scala is pretty verbose as well.
I would much prefer to write some like:
def pomSettings: PomSettings = (
description = artifactName(),
organization = "com.lihaoyi",
url = "https://github.com/com-lihaoyi/scalasql",
licenses = [MIT],
versionControl = github(
owner = "com-lihaoyi",
repo = "scalasql"
),
developers = [
(id = "lihaoyi", name = "Li Haoyi", url = "https://github.com/lihaoyi")
]
)