I’m going to chip in and say that the front page snippet should not be to show off language features.
The goal should be two things:
Show how the user can do things they already know they want to do, easily
- Create a class with fields/constructor on one line!
- Create lists, maps and sets on one line, and iterate/etc. over them!
- Define functions on one line!
- Run two computations in parallel in three lines! (using Futures)
Show how easy it is to solve small problems
- Breadth-first Search
- Make a trivial command-line app
- Make a simple web widget
These concerns are contradictory, but neither of them involves showing off how many features the language has. It’s not an uncommon feeling that the number of features Scala has is a disadvantage of using the language!
Ideally the snippet would show no features a newbie would not immediately understand. Abstract types, multiple-inheritance/trait-stacking, context bounds, implicits, and many other things can wait for later. The example can use them just fine, but they should not be necessary for understanding what the example is doing.
That said, I’m going to throw my hat in the ring and offer the Scala.js Oscilloscope:
18 lines of non-whitespace code, uses a lot of basic language features (
Seqs, anonymous functions, tuples, destructuring,
for-loops) and puts together something pretty in relatively few lines of code. A user can tweak this and get immediate feedback, e.g. changing the functions used to draw the graph or changing the colors used. And anyone can appreciate the output, not just people interested in a particular algorithm or technique.
I’m also going to vote for using ScalaFiddle instead of Scastie, even though that was not the original question. Apart from ScalaFiddle compiling code way faster than Scastie, Scastie also takes forever (almost 10 seconds!) to load over here in Singapore:
It appears the fault is split between lack of full optimizations on the JS blob, as well as lack of gzip compression on the server. Apart from initial download speed, ScalaFiddle does a bunch of things Scastie doesn’t, e.g. caching compilation output using a CDN for instant initial page loads that include running the compiled output.
Overall, ScalaFiddle ends up being a much slicker experience in the places where it matters, and the shortcomings are in places where it doesn’t matter. Newbies aren’t going to care that you can’t run code using
java.lang.ProcessBuilder in the “try it now!” sandbox, nor are they going to care that they can’t tweak SBT settings or compile using Dotty.
There’s a time and place for Scastie, when you want to reproduce more involved setups with custom SBT config and esoteric Scala versions. But for this use case, it seems ScalaFiddle is just the right tool for the job.