Flogging a dead horse - reading a number

Kenneth Fogel kfogel at dawsoncollege.qc.ca
Mon Jan 20 14:34:34 UTC 2025


I don’t think my suggestions break type safety. Have a read for doubles or allow transforming Strings to a number via casting still maintains type safety. Or, I could suggest:
double value = readln(“Give me a value”);
that implies that the String should be converted because of the declared type on the LHS. This would also restrict var as it depends on the type on the RHS.

Delusionally yours,
Ken
________________________________
From: Remi Forax <forax at univ-mlv.fr>
Sent: Sunday, January 19, 2025 1:15:42 PM
To: Kenneth Fogel <kfogel at dawsoncollege.qc.ca>
Cc: amber-dev <amber-dev at openjdk.org>
Subject: Re: Flogging a dead horse - reading a number



________________________________
From: "Kenneth Fogel" <kfogel at dawsoncollege.qc.ca>
To: "amber-dev" <amber-dev at openjdk.org>
Sent: Sunday, January 19, 2025 6:55:34 PM
Subject: Flogging a dead horse - reading a number

Hi,

Hello,


I have started a new course this past week, a first level Java course. Once we get past “Hello Moose” (in Canada we prefer this to Hello World) I present a simple program that calculates loan payments. Then I present an interactive version where I am forced to write:

    var loan = Double.parseDouble(readln("Loan: "));

    var interest = Double.parseDouble(readln("Interest: "));

    var term = Double.parseDouble(readln("Term: "));

Its all going well until I must describe what Double.parseDouble is.

I do not need a read for each numeric type. A read for doubles is all I think is necessary and then I could write:

    var loan = (readNum("Loan: "));  // loan is a double

or if I need an integer:

   var numberOfCarrots = (int)readNum(“How many carrots do you need? “);

Heck, if I were greedy, I’d ask that if you cast a readln this results in numeric input:

    var loan = (double) readln("Loan: "));  // Just like Python

Java is not a dynamically typed language, so no !
That's said, you are free to provide a library for your students.

In my case, with my students, we first go from readln/println to IO.readln()/IO.println() and then we add Integer.parseInt() and Double.parseDouble(),
so Double.parseDouble() is not alien at the time it is introduced.


But I’m not that greedy, today.

Ken

regards,
Rémi

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/amber-dev/attachments/20250120/3033c527/attachment-0001.htm>


More information about the amber-dev mailing list