JEP 477 Interacting with the Console
Remi Forax
forax at univ-mlv.fr
Tue Jul 16 06:41:15 UTC 2024
----- Original Message -----
> From: "cay horstmann" <cay.horstmann at gmail.com>
> To: "amber-dev" <amber-dev at openjdk.org>
> Sent: Monday, July 15, 2024 5:59:49 PM
> Subject: JEP 477 Interacting with the Console
Hello,
> I'd like to raise one more time the issue of simple console interaction.
>
> https://openjdk.org/jeps/477#Interacting-with-the-console puts up the strawman
> of
>
> try {
> BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
> String line = reader.readLine();
> ...
> } catch (IOException ioe) {
> ...
> }
>
> I don't think it is convincing to cite BufferedReader. I looked up the top five
> intro to Java books that make up the bulk of US college market. All use
> Scanner, not BufferedReader. It is easy to see why:
>
> * No checked exceptions
> * Can read numbers
>
> Scanner has issues (mixing nextInt/nextLine, localized number input vs.
> non-localized print), so I could, as an author and teacher, be convinced to
> change to something better.
yes,
at my uni, we use to use Scanner too.
>
> The appeal of short print/println/readln methods seems obvious. But now consider
> number input:
>
> int age = Integer.parseInt(readln("How old are you?"));
>
> A beginning student must realize in the first week or so of instruction:
>
> * There are static and instance methods
> * A static method can be
> * qualified by a class
> * unqualified due to static import
> * one of the static methods that is magically imported
> * but only in a source file containing an implicit class
>
> That's not conceptually simple.
>
> If the static methods that a beginner needs in the first few weeks (including
> parseInt, parseDouble, exit, and a handful of the Math methods) were all
> unqualified, then the beginner would be helped. Otherwise, you would help the
> beginner more by not statically importing IO by default. They can start out
> with IO.println, have a consistent mental model in those first few weeks, and
> learn static imports later.
or explain after having used print, println and readln, that those are just shortcuts for IO.print, IO.println and IO.readln,
after that, you can introduce Integer.parseInt. Going from println to IO.println is also the right place to introduce where to find the documentation, the online javadoc, etc.
>
> Or, if the focus is not the beginner, but the author of small programs, the JEP
> could state that as the motivation.
>
> In general, the needs of beginners and authors of small programs are not the
> same. The JEP bounces between the needs of the two. Implicit classes are useful
> for both, but magic imports will add puzzlement for beginners.
I disagree, this is only an issue if you talk about "import", seing println as a shorcut for IO.println is not a real problem.
The notion of "import" in Java is tricky anyway especially because most of my students know Python so you need a full lesson about the difference between Java import and Python import,
but that lesson can be taught in the second part of the semester when you need "package".
>
> Cheers,
>
> Cay
regards,
Rémi
>
> --
>
> Cay S. Horstmann | https://horstmann.com
More information about the amber-dev
mailing list