JEP 495 Question

Ron Pressler ron.pressler at oracle.com
Thu Nov 7 18:45:08 UTC 2024


This has been considered, and the decision, for the time being, is to err on the side of caution and not add such methods. While readln and println can be clearly described and happily used by both beginners and veterans writing scripts, this is not quite the case for methods for parsing numbers read as input.

For example, an implementation that does `return Integer.parseInt(readln(prompt))` is not that useful for veterans writing scripts as they may just as reasonably want to read, say, a CSV file, and parse multiple numbers per line. It is also not quite intuitive for beginners, either, who may expect the console line-editing functionality to prevent entering anything that isn’t an integer (or a floating-point number).

So such operations — however they’re defined — serve as bad primitives. While there’s no doubt that `Integer.parseInt(readln("Enter a number”))` is more characters for a beginner to type than `readlnInt(“Enter a number”)` it more clearly communicates that what is read is an arbitrary string that the program then attempts to parse as an integer, and that the latter operation may fail independently from the former.

So rather than adding convenience methods that perform some specific non-primitive operations (begging requests for adding others still) it’s best to wait a while and see what the most urgent issues encountered are in this new world before offering solutions for what may or may not be significant issues.

— Ron

> On 7 Nov 2024, at 17:06, Barry Burd <bburd at drew.edu> wrote:
> 
> I see that parameterless println() and readln() methods are being added to java.io.IO in JEP 495. I'm still wondering if there's been any thought to including methods like readInt and readDouble. In the early stage of an introduction to Java, it's common to have the student input int values and double values for simple examples. With the current spec, the best way to do this (as far as I can see) is
> 
>       var n = Integer.parseInt(readln("Enter a number"));
> 
> It seems natural to simplify this with a readInt method, and the addition of such a method wouldn't weigh heavily on the java.io.IO package.
> Any thoughts?
>   --Barry



More information about the amber-dev mailing list