Making io.StdIn.readLine imported by default

@velvetbaldmime was working on something similar: GitHub - neandertech/cue4s: Experimental library for CLI prompts in Scala 3, available on JS, JVM, and Native platforms

1 Like

Funny that cue4s came up twice in independent conversations in the last 7 days :slight_smile: cc @lbialy

The very simple task of making even a prompts clone in Scala for all 3 platforms has proven to be more difficult than I anticipated – but mostly due to my lack of experience with TUIs and how they work under the hood. I would love to help train more contributors to share the burden.

On the subject of this conversation: I agree with some of the posters that println has a much wider applicability than readLine, the latter being only near and dear to the hearts of classically trained computer science students, such as myself :stuck_out_tongue:

For people building actual apps, the console interactions of today are much more complex (see GitHub - charmbracelet/bubbletea: A powerful little TUI framework 🏗 for inspiration), and having readLine available without import would not move the needle in the slightest.

3 Likes

People seemed to be open to the idea to make “toolkits” more powerful.

I think this is actually not so difficult. The compiler has switches for almost everything discussed so far (besides the “setup scripts”). You can add global imports, or switch Predef.

So if “toolkits” could define compiler (or scala-cli) parameters I guess one could easily create customized environments just by using a “toolkit”.

The compiler call and all its details (Predef, -Yimports, compiler flags) would be hidden this way, which is quite beginner friendly.

I also don’t recall the last time I used readLine in Scala.

However, I think there might be a bit of a chicken and egg problem:

I feel like I would use readLn more often in my scripts (e.g. if an argument is missing), but I don’t because it’s cumbersome.
Which in turn might be the reason why most tooling/libraries have a nice support for arguments, but there’s not much options for interactive TUIs.

At least I think I would use cue4s in my scripts, if it wasn’t for the “Library is experimental and is only available in Sonatype Snapshots” part :stuck_out_tongue:

1 Like

I’m a Scala beginner who have Java experiences. I haven never called readLine function before.

Here are two toolkits help me to learn Scala with ease:

  1. Scala worksheet: It’s something like Jupyter notebook but much easier to use for beginners. And scastie is an online version of it. I can just install vscode’s extension and create a file named demo.worksheet.sc and start learning. IMO, for a beginner, Put literal values on the worksheet and see the results on demand is easier than using readLine (which may require type conversions)
  2. Scala-CLI: It makes adding dependencies easier for single file. The using directives also support worksheet, and I can explore libraries on-demand by combining Scala-CLI and worksheet.

Hope my experience can be helpful for this discussion.

5 Likes