SimpleIO in JEP draft 8323335

Remi Forax forax at univ-mlv.fr
Mon Feb 19 08:03:49 UTC 2024


----- Original Message -----
> From: "cay horstmann" <cay.horstmann at gmail.com>
> To: "amber-dev" <amber-dev at openjdk.org>
> Sent: Sunday, February 18, 2024 10:12:09 PM
> Subject: SimpleIO in JEP draft 8323335

> 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.

"input" is used in Python, but in Python, "print" means print and add a new line.

So either we are consistent with Python and we have "input"/"print" and no "println",
or we are more like the other IO methods in Java and use "println" and "readLine".

One can note that this is not fully consistent, because either "println" should be "printLine" or "readLine" should be "readln". But this is how Java actually works.

I also entertained the idea of using a varargs for "println" to avoid to teach "+" on string (or STR."") at the beginning, like console.log() does in JavaScript.
In that case, we can add an overload of the existing "println", like this
  static void println(Object first, Object... others) 

I think it has to be an overload because you still want to take a look to the javadoc of "readLine" and "println" without seeing any "..." and it can not be println(Object...) because it will magically works with arrays of objects but not with arrays of primitives.


In one hand, i'n not sure about that adding "println(Object, Object...)" is a good idea, we may want to keep it simple. In the other hand, i'm pretty sure "print" should be removed, because it's confusing to have both "print" and "println" (at least there is not "printf") and the semantics of "print" is not obvious for beginners ("println" and "readLine" are line oriented, but "print" is not).

> 
> Cheers,
> 
> Cay

regards,
Rémi

> 
> --
> 
> Cay S. Horstmann | http://horstmann.com | mailto:cay at horstmann.com


More information about the amber-dev mailing list