Improved main methods coming along
Taking a brief break from A Philosophy of Testing for a little bit of good old-fashioned Dotty news:
This morning, I noticed this Draft PR, titled “Generalize main annotations”. That’s pretty exciting. One of the nice features of Scala 3 is the new @main
annotation, which allows you to more-easily create application entry points, as documented here. But that annotation in its original form is good, but not great — when compared to something like Ammonite, it is notably lacking in the details.
This PR seems to go a long ways towards making up that ground. It’s an enormous PR (although most of the changes appear to be boilerplate tweaks to existing tests), but the most interesting stuff for the non-compiler-expert is in the test section, including tidbits like:
- Complex, auto-generated usage documentation.
- A bunch of examples of creating your own parameter parsers.
- Multiple entry points.
- Named parameters.
- Specifying the return type of the program. (Which gets printed out on exit.)
- Examples of improved error reporting for bad calls.
Overall, it’s pretty neat — increasingly, the @main
annotation works the way you would intuitively expect it to, and just “does the right thing”.
Usual caveat for Dotty news: this is just a draft PR, nowhere near merged into the mainline, much less released yet. But it realizes a promise made by the team some time back, to make @main
more generally useful and ergonomic, so it will hopefully make it to a Scala 3 release near you before too terribly long.