I have mentioned this in an earlier discussion, but since we are now allowing side-effecting top-level
vals, it only makes sense to allow side-effecting top-level statements
package p println("Hello World!")
This does several things:
Cleans up the syntax for something that is already allowed via
val meaninglessName = println("Hello World"), just without the meaningless names. This is a big wart with the meaningless
_ <- foosyntax in for-comprehensions, for example.
*.scalafile syntax closer towards Ammonite/Script/Worksheet/Mill
*.scsyntax or SBT’s
Converges the REPL and
Makes Scala easier to learn for novices: you can just write code and put it into a file, and run it. Just like Python, which is in many cases the gold-standard for ease-of-getting-started for programming beginners
Note that “novices” doesn’t just mean students: there is a large class of data scientists, analysts, system admins, devops, mathematicians, mechanical engineers, and others who would fall under the category of “professional novices”. These are people who use programming to supplement their main job but have neither the need nor desire to become experts in it. These are the sorts of people who would benefit greatly from being able to “just write code and run it”
Even within the existing Scala community, there is tons of evidence for existing demand for such a syntax: SBT, Mill, IntelliJ Worksheets, Scala-Fiddle, Scastie, Jupyter-Scala, and others have each re-invented their own flavor of it. Clearly, this is something which a lot of people want.
We have already had discussions about how to simplify the main method and make Scala less boilerplatey and easier to pick up for absolute beginners, who may be confused by
vals but not free-floating expressions/statements at the top of a file.
If we hope for Scala to be as approachable as the other languages that currently dominate the ease-of-learning, getting-started, and professional-novice scene, we should do what they do where-ever it makes sense, and this is one of them. In this case, the fact that it simplifies Scala itself in multiple different ways, narrowing the arbitrary differences in Scala syntax seen in different contexts, is just a (huge) bonus.