SimpleIO in JEP draft 8323335
Cay Horstmann
cay.horstmann at gmail.com
Sun Feb 18 21:12:09 UTC 2024
I would like to comment on the simplicity of https://openjdk.org/jeps/8323335 for beginning students.
I am the author of college texts for introductory programming. Like other authors, I introduce the Scanner class (and not Console) for reading user input. Given that students already know about System.out, it is simpler to call
System.out.print("How old are you? ");
int x = in.nextInt(); // in is a Scanner
than
int x = Integer.parseInt(console.readLine("How old are you? "));
or with the JEP draft:
int x = Integer.parseInt(input("How old are you? "));
Then again, having a prompt string is nice too, so I could imagine using the Console API with Integer.parseInt and Double.parseDouble, instead of Scanner.nextInt/nextDouble.
But why have a third API, i.e. "input"?
I think there are two feasible directions. Either embrace the Scanner API and next/nextInt/nextDouble/nextLine, or the Console API and readLine. Adding "input" into the mix is just clutter, and ambiguous clutter at that. At least readLine makes it clear that the entire line is consumed.
Cheers,
Cay
--
Cay S. Horstmann | http://horstmann.com | mailto:cay at horstmann.com
More information about the amber-dev
mailing list