SimpleIO in JEP draft 8323335

John Hendrikx hjohn at xs4all.nl
Wed Feb 21 23:50:07 UTC 2024


Hopefully not overstepping bounds, but as naming goes, I think 
`SystemIO` is a bit too ambitious a name.  For a class that interacts 
with the standard in and out streams, `StandardIO` seems a closer fit 
(although just like "System", "Simple" and "Basic", "Standard" is a very 
generic term that could mean almost anything).  If purely intended for 
on-ramp without much use cases beyond that, then I would go with 
`BasicIO` to indicate it provides only basic functionality which you 
will grow out of.

--John

------ Original Message ------
>From "Stephen Colebourne" <scolebourne at joda.org>
To "amber-dev" <amber-dev at openjdk.org>
Date 21/02/2024 23:04:48
Subject Re: SimpleIO in JEP draft 8323335

>I'd like to express basic agreement that reading and writing a string
>(and not more) is a good first API. But I also agree that it is
>potentially an on-ramp to nowhere.
>
>I'm also not at all happy with `input("How old are you? ")` which is
>doing two unrelated things (printing and reading a line)
>
>
>I'd like to throw out a left-field idea to the educators here -
>transformation via method reference.
>
>  printLine("Enter your age");
>  int age = readLine(Integer::parseInt);
>
>Obviously a method reference lambda is not a simple thing to explain
>fully, but it is short and direct. Perhaps in the initial learning
>stages you can get away without explaining exactly how
>Integer::parseInt operates?
>
>Suggested API:
>public final class SystemIO {
>   public static void printLine(Object obj) ...
>   public static void print(Object obj) ...
>   public static String readLine() throws UncheckedIOException ...
>   public static <T> T readLine(Function<String, T> transformer)
>throws UncheckedIOException ...
>}
>
>Stephen
>
>
>On Tue, 20 Feb 2024 at 19:32, Cay Horstmann <cay at horstmann.com> wrote:
>>
>>Hi Rémi,
>>
>>I am not bothered by the concepts that Scanner needs, because for me they are reasonable investments. As you point out, they are:
>>
>>* instance methods
>>* new
>>* import
>>
>>I would switch to a different approach if it (a) didn't introduce yet another fiddly special case (magic static import) and (b) wasn't unreasonably verbose. I would find this too painful:
>>
>>import java.util.SimpleIO;
>>
>>int age = Integer.parseInt(SimpleIO.input("How old are you? "));
>>
>>I could embrace the magic static import if it was sufficiently general and useful to pay for the complexity. Hence my suggestion
>>
>>int age = parseInt(input("How old are you? "));
>>
>>Or
>>
>>int age = readInt("How old are you? ");
>>
>>I need to make these decisions for the books and activities that I produce. As it is in the JEP today, I'd stick with Scanner. I would put in a note, just to signal that I know what is happening,  that as of Java 25 (?), you can also use input, but that it relies on another fiddly rule, and it doesn't transfer to file I/O, so why bother...
>>
>>My sentiment is just a data point. I understand that the cost/benefit model is different for everyone.
>>
>>Cheers,
>>
>>Cay
>>
>>PS. I'd like to register a forceful pushback on "parsing numbers is so crazily complex that we can't possibly deal with it". What does print/println produce for numbers? Is it the crazily complex localized number format? No--only printf applies localization. The print/println methods format numbers as Java literals. That's a settled issue. It's been like that since Java 1.0. Not crazily complex. A readInt/readDouble (or whatever it is called) in SimpleIO can surely be the canonical inverse of print/println.
>



More information about the amber-dev mailing list