On 20/06/2024 18:28, Michael S wrote:
On Thu, 20 Jun 2024 17:58:25 +0100
bart <bc@freeuk.com> wrote:
Python is supposed to a good beginner's language not a DIY one.
>
Python + its huge standard library is supposed to a good beginner's
language. Not the language in isolation.
That doesn't make a beginner's language; it's just makes it a language with a huge library.
The first program I ever wrote was an exercise involving reading three numbers from the terminal. I can't remember the exact syntax, but it wouldn't have been far off what I write now in my two languages:
readln a, b, c
In Python it's something like this (from Stackoverflow):
a, b, c = map(int, input().split())
Another answer said:
a, b, c = [int(v) for v in input().split()]
If a, b, c are floats, or strings, or a known combination, or (in a dynamic language) they can be mixed, then it's all different.
Oh, and you have to use whitespace to separate; commas will need extra work; you need to go and look at the specs for 'split'.
The input also needs exactly three values, but you might want to read the first value, then decided what to read next based on that.
Hardly intuitive, is it? My read/readln /statements/ are strictly line-oriented. If I run this script:
repeat
print "? "
readln a, b, c
fprintln "<#> <#> <#>", a, b, c
println a.type, b.type, c.type
println
until not a
Then this is a session:
? 1 2 3
<1> <2> <3>
int int int
? 1 2.3 abc
<1> <2.300000> <abc>
int real string
? 1234
<1234> <> <>
int string string
? "1 2 3" 4 5
<1 2 3> <4> <5>
string int int
? 1,2,3,4,5
<1> <2> <3>
int int int
? 6,7
<6> <7> <>
int int string
? 999999999999999999999999999999999999999999999999 20 30
<999999999999999999999999999999999999999999999999> <20> <30>
decimal int int
That simple Python line, with or without the conversion to numbers, will choke on most such examples. The 'beginner' now needs to become an expert on string processing to do simple input.
This script is in dynamic code. In static code, a, b, c will have fixed types, eg. all ints, but float inputs are converted as needed.
So does C fare? I tried this:
int a,b,c;
while (1) {
printf("? ");
scanf("%d %d %d", &a, &b, &c);
printf("<%d> <%d> <%d>\n\n", a, b, c);
}
This is a session:
? 1 2 3
<1> <2> <3>
? 1, 2, 3
So far so good, but I haven't yet pressed Enter at this point; when I do, it just loops forever showing '? <1> <2> <3>'. Start again:
? 1 2.3 0
It loops again. I will take out the loop and just do one line per run!
? 1 2.3 4
<1> <2> <0>
Oh dear. Plus it screws something up so that lines get out of sync. Let's try doubles:
? 9223372036854775807 2 3
<9223372036854775800.000000> <2.000000> <3.000000>
Hmm...