Discussion:
Simple Pascal question
(too old to reply)
Arne Vajhøj
2024-08-01 19:42:10 UTC
Permalink
How does one assign a non-integer to an explicit floating
point type variable?

$ type z.pas
program z(input,output);

var
x : f_float;

begin
x := 1;
writeln(x);
end.
$ pas z
$ lin z
$ r z
1.00000E+00
$ type zz.pas
program z(input,output);

var
x : f_float;

begin
x := 1.5;
writeln(x);
end.
$ pas zz

x := 1.5;
.....^
%PASCAL-E-OPNDASSCOM, Operands are not assignment compatible
at line number 7 in file DKA0:[arne.vmsjava.tig]zz.pas;3
%PASCAL-E-ENDDIAGS, PASCAL completed with 1 diagnostic

Arne
Uli Bellgardt
2024-08-02 04:25:26 UTC
Permalink
The value 1.5 should be an f_float value as well:

$ type zzz.pas
program z(input,output);

var
x : f_float;

begin
x := %f_float 1.5;
writeln(x);
end.

$ pas zzz
$ link zzz
$ run zzz
1.50000E+00
Scott Dorsey
2024-08-03 17:32:16 UTC
Permalink
Post by Uli Bellgardt
$ type zzz.pas
program z(input,output);
var
x : f_float;
This seems very strange to me... Pascal isn't supposed to have such
strong typing, is it? I don't remember ever having to manually coerce
anything. Or is f_float sufficiently different from a normal float?
--scott
--
"C'est un Nagra. C'est suisse, et tres, tres precis."
Arne Vajhøj
2024-08-03 18:40:32 UTC
Permalink
Post by Scott Dorsey
Post by Uli Bellgardt
$ type zzz.pas
program z(input,output);
var
x : f_float;
This seems very strange to me... Pascal isn't supposed to have such
strong typing, is it? I don't remember ever having to manually coerce
anything. Or is f_float sufficiently different from a normal float?
The intended way in Pascal is to use real and double and
let compiler switch determine implementation.

/float=d_f -> F & D
/float=g_f -> F & G
/float=ieee -> S & T

But Pascal also allows for being more explicit.

To quote from the manual:

<quote>
VSI Pascal provides the following built-in data types to declare
variables of a specific floating point type regardless of the /FLOAT
setting on the command line (or FLOAT attribute on the MODULE):

F_FLOAT
D_FLOAT
G_FLOAT
S_FLOAT
T_FLOAT
X_FLOAT
</quote>

And I "forgot" to read a half page ahead and find:

<quote>
The floating lexical functions %F_FLOAT, %D_FLOAT, %G_FLOAT, %S_FLOAT,
and %T_FLOAT can be prefixed on a floating constant to select the
floating type regardless of any module-level attribute or command line
selection.
</quote>

Arne
Dan Cross
2024-08-04 12:22:01 UTC
Permalink
Post by Scott Dorsey
Post by Uli Bellgardt
$ type zzz.pas
program z(input,output);
var
x : f_float;
This seems very strange to me... Pascal isn't supposed to have such
strong typing, is it? I don't remember ever having to manually coerce
anything. Or is f_float sufficiently different from a normal float?
Just to touch on the Pascal point itself, one of that language's
hallmarks is almost excessive rigidity in how it treats types.
While integer->float conversions are implicit, the opposite is
not. I think that the general rule is that when a type "widens"
conversion is implicitly ok (so in mathematics, when the
integers are a proper subset of the reals, so every integer is
already a real, and implicit conversion from int to real is
intuitive, even though representations on physical computers
aren't quite so neat for implementation reasons), but when types
narrow, as in when going from real to int, one must exercise
more caution.

An old annoyance about Pascal was that the size of an array is
part of it's type, which makes writing functions and procedures
that work across differently sized arrays challenging.
Interesting, this has become du jour again in modern languages,
but those tend to provide access to a `slice` type that provides
a window onto the underly array, and implicitly encodes a
length (and usually a "capacity"). This makes working with
arrays in such languages very convenient.

- Dan C.
Arne Vajhøj
2024-08-04 14:51:20 UTC
Permalink
Post by Dan Cross
Post by Scott Dorsey
Post by Uli Bellgardt
$ type zzz.pas
program z(input,output);
var
x : f_float;
This seems very strange to me... Pascal isn't supposed to have such
strong typing, is it? I don't remember ever having to manually coerce
anything. Or is f_float sufficiently different from a normal float?
Just to touch on the Pascal point itself, one of that language's
hallmarks is almost excessive rigidity in how it treats types.
Ada is even more strict.
Post by Dan Cross
While integer->float conversions are implicit, the opposite is
not. I think that the general rule is that when a type "widens"
conversion is implicitly ok (so in mathematics, when the
integers are a proper subset of the reals, so every integer is
already a real, and implicit conversion from int to real is
intuitive, even though representations on physical computers
aren't quite so neat for implementation reasons), but when types
narrow, as in when going from real to int, one must exercise
more caution.
Such a restriction is rather common today.

Random example:

$ javac Z.java
Z.java:6: error: incompatible types: possible lossy conversion from
double to int
iv = xv;
^
1 error
Post by Dan Cross
An old annoyance about Pascal was that the size of an array is
part of it's type, which makes writing functions and procedures
that work across differently sized arrays challenging.
In original Wirth Pascal. Most implementations has solutions.

VMS:

program flex_array(input, output);

procedure dump(a : array[lb..ub:integer] of integer);

var
i : integer;

begin
for i := lbound(a) to hbound(a) do begin
write(' ', a[i]:1);
end;
writeln;
end;

var
a1 : array [1..1] of integer value [ 1: 1 ];
a2 : array [2..3] of integer value [ 2: 1; 3: 2 ];
a3 : array [4..6] of integer value [ 4: 1; 5: 2; 6: 3 ];

begin
dump(a1);
dump(a2);
dump(a3);
end.

FPC/Lazarus:

program flex_array(input, output);

procedure dump(a : array of integer);

var
i : integer;

begin
for i := low(a) to high(a) do begin
write(' ', a[i]:1);
end;
writeln;
end;

var
a1 : array [1..1] of integer = ( 1 );
a2 : array [2..3] of integer = ( 1, 2 );
a3 : array [4..6] of integer = ( 1, 2, 3 );

begin
dump(a1);
dump(a2);
dump(a3);
end.
Post by Dan Cross
Interesting, this has become du jour again in modern languages,
but those tend to provide access to a `slice` type that provides
a window onto the underly array, and implicitly encodes a
length (and usually a "capacity"). This makes working with
arrays in such languages very convenient.
Different people may have different opinions on what is a modern
language.

But a lot of the widely used static typed languages does not
have any problems with arrays of different lengths as they
are treated as objects.

Like:

public class FlexArray {
private static void dump(int[] a) {
for(int v : a) {
System.out.printf(" %d", v);
}
System.out.println();
}
public static void main(String[] args) throws Exception {
int[] a1 = { 1 };
int[] a2 = { 1, 2 };
int[] a3 = { 1, 2, 3 };
dump(a1);
dump(a2);
dump(a3);
}
}

Arne
Lawrence D'Oliveiro
2024-08-04 22:19:03 UTC
Permalink
Post by Arne Vajhøj
An old annoyance about Pascal was that the size of an array is part of
it's type, which makes writing functions and procedures that work
across differently sized arrays challenging.
In original Wirth Pascal. Most implementations has solutions.
ISO Pascal added “conformant arrays”, where the array bounds were passed
as separate arguments. I don’t think you ever saw these on the micros,
which persisted with their UCSD-Pascal derivatives. But you did on the
bigger machines.

Also I didn’t know before, but there is an official spec for “Extended
Pascal”, too: ISO 10206.
Arne Vajhøj
2024-08-04 23:55:02 UTC
Permalink
Post by Lawrence D'Oliveiro
Post by Arne Vajhøj
An old annoyance about Pascal was that the size of an array is part of
it's type, which makes writing functions and procedures that work
across differently sized arrays challenging.
In original Wirth Pascal. Most implementations has solutions.
ISO Pascal added “conformant arrays”, where the array bounds were passed
as separate arguments.
I thought that on VMS this was done by passing an array descriptor and
not by pass extra arguments. dsc$descriptor_a etc..
Post by Lawrence D'Oliveiro
I don’t think you ever saw these on the micros,
which persisted with their UCSD-Pascal derivatives. But you did on the
bigger machines.
They made an even easier solution: not specifying index at all.

See FPC code posted earlier.

Arne
Lawrence D'Oliveiro
2024-08-05 02:41:44 UTC
Permalink
Post by Arne Vajhøj
Post by Lawrence D'Oliveiro
ISO Pascal added “conformant arrays”, where the array bounds were
passed as separate arguments.
I thought that on VMS this was done by passing an array descriptor and
not by pass extra arguments. dsc$descriptor_a etc..
That’s an implementation issue.
John Reagan
2024-08-05 04:18:32 UTC
Permalink
Post by Lawrence D'Oliveiro
Post by Arne Vajhøj
An old annoyance about Pascal was that the size of an array is part of
it's type, which makes writing functions and procedures that work
across differently sized arrays challenging.
In original Wirth Pascal. Most implementations has solutions.
ISO Pascal added “conformant arrays”, where the array bounds were passed
as separate arguments. I don’t think you ever saw these on the micros,
which persisted with their UCSD-Pascal derivatives. But you did on the
bigger machines.
Also I didn’t know before, but there is an official spec for “Extended
Pascal”, too: ISO 10206.
Yes, the preface to ISO 10206 has lots of project history and why we
ended up with a separate document instead of just extending ISO 7185.

And for those who don't have a copy (IEEE still holds the copyright),
you'll find:

The eff orts are acknowledged of all those who contributed to the work
of JPC, and in particular:

Thomas N. Turba Chairman X3J9
Michael Patrick Hagerty Chairman IEEE P770
John R. Reagan Secretary

followed by a lengthy list of names including Steve Hobbs who was the
VAX Pascal V2 project leader.

And there was also a follow-up annex to ISO 10206 with object oriented
extensions that I think nobody every implemented.
Dan Cross
2024-08-05 00:09:48 UTC
Permalink
Post by Arne Vajhøj
Post by Dan Cross
Post by Scott Dorsey
Post by Uli Bellgardt
$ type zzz.pas
program z(input,output);
var
x : f_float;
This seems very strange to me... Pascal isn't supposed to have such
strong typing, is it? I don't remember ever having to manually coerce
anything. Or is f_float sufficiently different from a normal float?
Just to touch on the Pascal point itself, one of that language's
hallmarks is almost excessive rigidity in how it treats types.
Ada is even more strict.
Rust even more so.
Post by Arne Vajhøj
Post by Dan Cross
While integer->float conversions are implicit, the opposite is
not. I think that the general rule is that when a type "widens"
conversion is implicitly ok (so in mathematics, when the
integers are a proper subset of the reals, so every integer is
already a real, and implicit conversion from int to real is
intuitive, even though representations on physical computers
aren't quite so neat for implementation reasons), but when types
narrow, as in when going from real to int, one must exercise
more caution.
Such a restriction is rather common today.
Yup. Because it turns out that it's usually a good idea. Even
among integers implicit conversions can be surprisingly lossy,
if one is converting to a narrower type.
Post by Arne Vajhøj
Post by Dan Cross
An old annoyance about Pascal was that the size of an array is
part of it's type, which makes writing functions and procedures
that work across differently sized arrays challenging.
In original Wirth Pascal. Most implementations has solutions.
Note I said "an old annoyance". Emphasis on old.
https://www.cs.virginia.edu/~evans/cs655/readings/bwk-on-pascal.html

Of course, to do practical work, people extended the language.
E.g., TurboPascal.
Post by Arne Vajhøj
[snip]
Post by Dan Cross
Interesting, this has become du jour again in modern languages,
but those tend to provide access to a `slice` type that provides
a window onto the underly array, and implicitly encodes a
length (and usually a "capacity"). This makes working with
arrays in such languages very convenient.
Different people may have different opinions on what is a modern
language.
Designed in this century.
Post by Arne Vajhøj
But a lot of the widely used static typed languages does not
have any problems with arrays of different lengths as they
are treated as objects.
Like I said, modern languages make this a solved problem.
Post by Arne Vajhøj
public class FlexArray {
private static void dump(int[] a) {
for(int v : a) {
System.out.printf(" %d", v);
}
System.out.println();
}
public static void main(String[] args) throws Exception {
int[] a1 = { 1 };
int[] a2 = { 1, 2 };
int[] a3 = { 1, 2, 3 };
dump(a1);
dump(a2);
dump(a3);
}
}
Java arrays are more like the aforementioned slices.

- Dan C.
Arne Vajhøj
2024-08-05 01:00:35 UTC
Permalink
Post by Dan Cross
Post by Arne Vajhøj
Post by Dan Cross
Interesting, this has become du jour again in modern languages,
but those tend to provide access to a `slice` type that provides
a window onto the underly array, and implicitly encodes a
length (and usually a "capacity"). This makes working with
arrays in such languages very convenient.
Different people may have different opinions on what is a modern
language.
Designed in this century.
That rules out Java.

But there are still languages like C#, Scala and Kotlin.
Post by Dan Cross
Post by Arne Vajhøj
But a lot of the widely used static typed languages does not
have any problems with arrays of different lengths as they
are treated as objects.
Like I said, modern languages make this a solved problem.
But C#, Scala and Kotlin also just allows for passing any length
arrays to methods taking an array.
Post by Dan Cross
Post by Arne Vajhøj
public class FlexArray {
private static void dump(int[] a) {
for(int v : a) {
System.out.printf(" %d", v);
}
System.out.println();
}
public static void main(String[] args) throws Exception {
int[] a1 = { 1 };
int[] a2 = { 1, 2 };
int[] a3 = { 1, 2, 3 };
dump(a1);
dump(a2);
dump(a3);
}
}
Java arrays are more like the aforementioned slices.
I don't think so.

Java does not have anything like slices.

C# does.

C# Span is similar to slices. But C# Span and C# array are far from
the same.

Arne
Dan Cross
2024-08-05 01:58:04 UTC
Permalink
Post by Arne Vajhøj
Post by Dan Cross
Post by Arne Vajhøj
Post by Dan Cross
Interesting, this has become du jour again in modern languages,
but those tend to provide access to a `slice` type that provides
a window onto the underly array, and implicitly encodes a
length (and usually a "capacity"). This makes working with
arrays in such languages very convenient.
Different people may have different opinions on what is a modern
language.
Designed in this century.
That rules out Java.
Agreed. Java is not very modern by, er, modern standards.
Post by Arne Vajhøj
But there are still languages like C#, Scala and Kotlin.
Or Rust, Go, Zig, etc.
Post by Arne Vajhøj
Post by Dan Cross
Post by Arne Vajhøj
But a lot of the widely used static typed languages does not
have any problems with arrays of different lengths as they
are treated as objects.
Like I said, modern languages make this a solved problem.
But C#, Scala and Kotlin also just allows for passing any length
arrays to methods taking an array.
Like I said, modern languages solved the problem.
Post by Arne Vajhøj
Post by Dan Cross
Post by Arne Vajhøj
public class FlexArray {
private static void dump(int[] a) {
for(int v : a) {
System.out.printf(" %d", v);
}
System.out.println();
}
public static void main(String[] args) throws Exception {
int[] a1 = { 1 };
int[] a2 = { 1, 2 };
int[] a3 = { 1, 2, 3 };
dump(a1);
dump(a2);
dump(a3);
}
}
Java arrays are more like the aforementioned slices.
I don't think so.
Java does not have anything like slices.
An array in Java is a pointer and a length. A slice is a
pointer and a length.
Post by Arne Vajhøj
C# does.
C# Span is similar to slices. But C# Span and C# array are far from
the same.
You have some studying to do. :-)

- Dan C.
Arne Vajhøj
2024-08-06 23:46:24 UTC
Permalink
Post by Dan Cross
Post by Arne Vajhøj
Post by Dan Cross
Post by Arne Vajhøj
public class FlexArray {
private static void dump(int[] a) {
for(int v : a) {
System.out.printf(" %d", v);
}
System.out.println();
}
public static void main(String[] args) throws Exception {
int[] a1 = { 1 };
int[] a2 = { 1, 2 };
int[] a3 = { 1, 2, 3 };
dump(a1);
dump(a2);
dump(a3);
}
}
Java arrays are more like the aforementioned slices.
I don't think so.
Java does not have anything like slices.
An array in Java is a pointer and a length. A slice is a
pointer and a length.
An array in Java is an object containing data type, array
length and all the elements.

Which is not the same as a structure containing a
pointer to somewhere in another object and a length.

Arne
Dan Cross
2024-08-08 05:33:01 UTC
Permalink
Post by Arne Vajhøj
Post by Dan Cross
Post by Arne Vajhøj
Post by Dan Cross
Post by Arne Vajhøj
public class FlexArray {
private static void dump(int[] a) {
for(int v : a) {
System.out.printf(" %d", v);
}
System.out.println();
}
public static void main(String[] args) throws Exception {
int[] a1 = { 1 };
int[] a2 = { 1, 2 };
int[] a3 = { 1, 2, 3 };
dump(a1);
dump(a2);
dump(a3);
}
}
Java arrays are more like the aforementioned slices.
I don't think so.
Java does not have anything like slices.
An array in Java is a pointer and a length. A slice is a
pointer and a length.
An array in Java is an object containing data type, array
length and all the elements.
Which is not the same as a structure containing a
pointer to somewhere in another object and a length.
Like I said, you should go learn a little bit about
language design. You're thinking is muddled with object
oriented paradigms, whether they apply or not.

- Dan C.
Lawrence D'Oliveiro
2024-08-05 02:44:19 UTC
Permalink
Post by Arne Vajhøj
Post by Dan Cross
Post by Arne Vajhøj
Different people may have different opinions on what is a modern
language.
Designed in this century.
That rules out Java.
My criterion is not when it was designed, but how well it has kept up with
modern thought on good language features.

By this criterion, I would say the Lisp family still counts as “modern”.
Even Perl is still worthy of respect. And Python of course deserves its
popularity.
Michael S
2024-08-05 12:34:49 UTC
Permalink
On Sun, 4 Aug 2024 21:00:35 -0400
Post by Arne Vajhøj
Post by Dan Cross
Post by Arne Vajhøj
Post by Dan Cross
Interesting, this has become du jour again in modern languages,
but those tend to provide access to a `slice` type that provides
a window onto the underly array, and implicitly encodes a
length (and usually a "capacity"). This makes working with
arrays in such languages very convenient.
Different people may have different opinions on what is a modern
language.
Designed in this century.
That rules out Java.
But there are still languages like C#, Scala and Kotlin.
Post by Dan Cross
Post by Arne Vajhøj
But a lot of the widely used static typed languages does not
have any problems with arrays of different lengths as they
are treated as objects.
Like I said, modern languages make this a solved problem.
But C#, Scala and Kotlin also just allows for passing any length
arrays to methods taking an array.
Post by Dan Cross
Post by Arne Vajhøj
public class FlexArray {
private static void dump(int[] a) {
for(int v : a) {
System.out.printf(" %d", v);
}
System.out.println();
}
public static void main(String[] args) throws Exception {
int[] a1 = { 1 };
int[] a2 = { 1, 2 };
int[] a3 = { 1, 2, 3 };
dump(a1);
dump(a2);
dump(a3);
}
}
Java arrays are more like the aforementioned slices.
I don't think so.
Java does not have anything like slices.
C# does.
Pay attention that despite being designed (or at least brought to
public) in this century, C# originally lacked slices.
They were added relatively recently, in v. 8.0, and referred in c# docs
as "Indices and ranges".
Post by Arne Vajhøj
C# Span is similar to slices. But C# Span and C# array are far from
the same.
Arne
Lawrence D'Oliveiro
2024-08-05 21:29:26 UTC
Permalink
Post by Michael S
Pay attention that despite being designed (or at least brought to
public) in this century, C# originally lacked slices.
The whole C♯/Dotnet thing just seems like a corporate vanity project on
the part of Microsoft, after they had their knuckles rapped by Sun over
trying to subvert Java. Microsoft themselves will not use Dotnet for
anything important (e.g. Microsoft Office). Their one time trying to do so
(Windows Vista) ended in disaster.
Arne Vajhøj
2024-08-07 00:13:07 UTC
Permalink
Post by Lawrence D'Oliveiro
Post by Michael S
Pay attention that despite being designed (or at least brought to
public) in this century, C# originally lacked slices.
The whole C♯/Dotnet thing just seems like a corporate vanity project on
the part of Microsoft, after they had their knuckles rapped by Sun over
trying to subvert Java. Microsoft themselves will not use Dotnet for
anything important (e.g. Microsoft Office). Their one time trying to do so
(Windows Vista) ended in disaster.
It is my impression that MS use .NET for a lot of their newer stuff.

Web version of Office, SharePoint, web server, ERP/CRM
(Dynamics), games, development tools (except VS Code that is
node/JavaScript based) and and all their web sites (except LinkedIn that
is a Java shop and GitHub that is RoR/Ruby) are all big users of
.NET and important for Microsoft.

The older stuff like Windows, the desktop version of Office, SQLServer
etc. has not been rewritten in C#/.NET, which sort of makes sense.

Rewriting such large code bases big bang style is very risky. Rewriting
them piece wise require integration - and the only viable integration
mechanism would be COM - rewriting from C++ to C# but sticking with COM
instead of a true .NET mechanism like MEF of MAF would be rather
pointless.

Furthermore C# would not be the right language for the lower levels
of Windows. They are going for Rust instead.

Arne
Arne Vajhøj
2024-08-06 23:57:50 UTC
Permalink
Post by Michael S
On Sun, 4 Aug 2024 21:00:35 -0400
Post by Arne Vajhøj
Post by Dan Cross
Post by Arne Vajhøj
public class FlexArray {
private static void dump(int[] a) {
for(int v : a) {
System.out.printf(" %d", v);
}
System.out.println();
}
public static void main(String[] args) throws Exception {
int[] a1 = { 1 };
int[] a2 = { 1, 2 };
int[] a3 = { 1, 2, 3 };
dump(a1);
dump(a2);
dump(a3);
}
}
Java arrays are more like the aforementioned slices.
I don't think so.
Java does not have anything like slices.
C# does.
C# Span is similar to slices. But C# Span and C# array are far from
the same.
Pay attention that despite being designed (or at least brought to
public) in this century, C# originally lacked slices.
They were added relatively recently, in v. 8.0, and referred in c# docs
as "Indices and ranges".
I thought it was C# 7.2.

It is important to note that C# Span and Range are
a little bit different than similar syntax in some of
the newer native languages supporting slice.

int[] a = { 10, 20, 30, 40, 50, 60, 70, 80, 90, 100 };
Span<int> s1 = a[1..3];

does not create a span/slice/view of the second and third
element of a - it allocates a new array of length 2,
copy the second and third element of a to it and
create a span/slice/view of the new array.

Span<int> s2 = ((Span<int>)a).Slice(1, 2);
Span<int> s3 = (new Span<int>(a)).Slice(1, 2);
Span<int> s4 = new Span<int>(a, 1, 2);

all create a span/slice/view of the second and third
element of a.

Arne
Arne Vajhøj
2024-08-07 00:27:53 UTC
Permalink
Post by Arne Vajhøj
Post by Michael S
On Sun, 4 Aug 2024 21:00:35 -0400
Post by Arne Vajhøj
C# Span is similar to slices. But C# Span and C# array are far from
the same.
Pay attention that despite being designed (or at least brought to
public) in this century, C# originally lacked slices.
They were added relatively recently, in v. 8.0, and referred in c# docs
as "Indices and ranges".
I thought it was C# 7.2.
Let me correct myself.

Span was 7.2, but range was 8.0.

Span is a "view slice" similar to slice in some of the newer
native languages.

Range is a "copy slice".

Arne
Arne Vajhøj
2024-08-07 20:12:48 UTC
Permalink
Post by Arne Vajhøj
Java does not have anything like slices.
Let me correct that.

Java 22 actually introduced something similar (started as
preview back in Java 14).

But it looks absolutely horrible!

import java.lang.foreign.MemorySegment;
import java.lang.foreign.ValueLayout;

public class SliceFun {
public static void dump(String lbl, MemorySegment ms) {
System.out.printf("%s : ", lbl);
for(int i = 0; i < ms.byteSize() /
ValueLayout.JAVA_INT.byteSize(); i++) {
System.out.printf(" %d",
ms.getAtIndex(ValueLayout.JAVA_INT, i));
}
System.out.println();
}
public static void main(String[] args) {
int[] a = { 1, 2, 3, 4, 5 };
MemorySegment ms = MemorySegment.ofArray(a);
dump("All", ms);
dump("Middle", ms.asSlice(1 * ValueLayout.JAVA_INT.byteSize(),
3 * ValueLayout.JAVA_INT.byteSize()));
}
}

Arne
Lawrence D'Oliveiro
2024-08-07 21:35:23 UTC
Permalink
Post by Arne Vajhøj
But it looks absolutely horrible!
Everything in Java looks absolutely horrible.

Trying to do select/poll? There’s something like 4 different classes and I
don’t know how many methods involved.

Trying to do SSL connections with private CA certs? Takes a bunch of
different classes (key stores, key managers, trust managers, factories for
key managers and trust managers, and what not) and over a hundred lines of
code.

Dates/times? You have to contend with an API that has accumulated so much
legacy cruft, that you are left with an old class where every single
member is deprecated, yet the class itself is still needed in the newer-
style calls.
Arne Vajhøj
2024-08-08 00:11:21 UTC
Permalink
Post by Lawrence D'Oliveiro
Dates/times? You have to contend with an API that has accumulated so much
legacy cruft, that you are left with an old class where every single
member is deprecated, yet the class itself is still needed in the newer-
style calls.
That is also one of Roland's pet peeves.

But it should not be that hard.

There are 3 generations of time API in Java:
* java.util.Date (Java 1.0)
* java.util.Date + java.util.*Calendar + java.text.*DateFormat
(Java 1.1 - 1.7)
* java.util.time.* (Java 1.8-)

But if we look at the second, then the trick is to realize
the mapping of functionality.

java.util.Date ~ C time_t type and time function
java.util.Calendar/GregorianCalendar ~ C mktime/gmtime/localtime
java.text.DateFormat/SimpleDateFormat ~ C strftime/strptime

Even though all the conversion functionality was moved from
Date to Calendar, then Date is still the basic point in time
type - the time_t of Java. So it did not go away.

Arne
Simon Clubley
2024-08-08 12:13:04 UTC
Permalink
Post by Arne Vajhøj
Post by Lawrence D'Oliveiro
Dates/times? You have to contend with an API that has accumulated so much
legacy cruft, that you are left with an old class where every single
member is deprecated, yet the class itself is still needed in the newer-
style calls.
That is also one of Roland's pet peeves.
Now try parsing JSON using the supplied builtin Java libraries
on Android. :-)

There is a solution but it is not as clean as elsewhere.

Simon.
--
Simon Clubley, ***@remove_me.eisner.decus.org-Earth.UFP
Walking destinations on a map are further away than they appear.
Arne Vajhøj
2024-08-08 12:57:20 UTC
Permalink
Post by Simon Clubley
Post by Arne Vajhøj
Post by Lawrence D'Oliveiro
Dates/times? You have to contend with an API that has accumulated so much
legacy cruft, that you are left with an old class where every single
member is deprecated, yet the class itself is still needed in the newer-
style calls.
That is also one of Roland's pet peeves.
Now try parsing JSON using the supplied builtin Java libraries
on Android. :-)
There is a solution but it is not as clean as elsewhere.
I would use binding instead of parsing.

I have never done anything on Android, but I would
expect both JSON-B and Jackson to work on Android

JSON-B is:

Jsonb b = JsonbBuilder.create();
X o = b.fromJson(jsonstr, X.class);

Jackson is:

ObjectMapper om = new ObjectMapper();
X o = om.readValue(jsonstr, X.class);

It don't get much easier than that.

You can of course ask why it did not become part of standard
Java SE.

For timeline/random reasons JSON-B became part of Java EE
not Java SE.

Arne
Arne Vajhøj
2024-08-08 13:00:25 UTC
Permalink
Post by Arne Vajhøj
Post by Simon Clubley
Post by Arne Vajhøj
Post by Lawrence D'Oliveiro
Dates/times? You have to contend with an API that has accumulated so much
legacy cruft, that you are left with an old class where every single
member is deprecated, yet the class itself is still needed in the newer-
style calls.
That is also one of Roland's pet peeves.
Now try parsing JSON using the supplied builtin Java libraries
on Android. :-)
There is a solution but it is not as clean as elsewhere.
I would use binding instead of parsing.
I have never done anything on Android, but I would
expect both JSON-B and Jackson to work on Android
Jsonb b = JsonbBuilder.create();
X o = b.fromJson(jsonstr, X.class);
ObjectMapper om = new ObjectMapper();
X o = om.readValue(jsonstr, X.class);
It don't get much easier than that.
You can of course ask why it did not become part of standard
Java SE.
For timeline/random reasons JSON-B became part of Java EE
not Java SE.
And just to be clear: the JSON-B specification is part of
Java EE not Java SE, but JSON-B libraries works fine in
Java SE - you just need to get them separately.

Arne
Simon Clubley
2024-08-09 12:47:41 UTC
Permalink
Post by Arne Vajhøj
Post by Simon Clubley
Post by Arne Vajhøj
Post by Lawrence D'Oliveiro
Dates/times? You have to contend with an API that has accumulated so much
legacy cruft, that you are left with an old class where every single
member is deprecated, yet the class itself is still needed in the newer-
style calls.
That is also one of Roland's pet peeves.
Now try parsing JSON using the supplied builtin Java libraries
on Android. :-)
There is a solution but it is not as clean as elsewhere.
I would use binding instead of parsing.
I have never done anything on Android, but I would
expect both JSON-B and Jackson to work on Android
I like to avoid using third-party libraries when possible.
Post by Arne Vajhøj
Jsonb b = JsonbBuilder.create();
X o = b.fromJson(jsonstr, X.class);
ObjectMapper om = new ObjectMapper();
X o = om.readValue(jsonstr, X.class);
It don't get much easier than that.
For comparison, here are the two built-in options available on Android
that I know about:

https://developer.android.com/reference/android/util/JsonReader
https://developer.android.com/reference/org/json/package-summary

Simon.
--
Simon Clubley, ***@remove_me.eisner.decus.org-Earth.UFP
Walking destinations on a map are further away than they appear.
Arne Vajhøj
2024-08-09 14:25:28 UTC
Permalink
Post by Simon Clubley
Post by Arne Vajhøj
Post by Simon Clubley
Post by Arne Vajhøj
Post by Lawrence D'Oliveiro
Dates/times? You have to contend with an API that has accumulated so much
legacy cruft, that you are left with an old class where every single
member is deprecated, yet the class itself is still needed in the newer-
style calls.
That is also one of Roland's pet peeves.
Now try parsing JSON using the supplied builtin Java libraries
on Android. :-)
There is a solution but it is not as clean as elsewhere.
I would use binding instead of parsing.
I have never done anything on Android, but I would
expect both JSON-B and Jackson to work on Android
I like to avoid using third-party libraries when possible.
You will have to evaluate benefits vs added size and management.
Post by Simon Clubley
Post by Arne Vajhøj
Jsonb b = JsonbBuilder.create();
X o = b.fromJson(jsonstr, X.class);
ObjectMapper om = new ObjectMapper();
X o = om.readValue(jsonstr, X.class);
It don't get much easier than that.
I would probably have listed GSON as well:

Gson gson = new Gson();
X o = gson.fromJson(jsonstr, X.class);

GSON is Google.

But apparently a different team in Google than the one
that does Android.
Post by Simon Clubley
For comparison, here are the two built-in options available on Android
https://developer.android.com/reference/android/util/JsonReader
https://developer.android.com/reference/org/json/package-summary
There are 4 types of API's for this:
1) Tree
2) Class binding
3) Streaming
A) Pull
B) Push

android.util.JsonReader is a 3A.

org.json.* is a 1.

Given that:
* 1 is cumbersome
* 2 is what you want
* 3A is a PITA
* 3B is a huge PITA

Then I suggest you bite the bullet and go for an external library
that supports class binding.

GSON is less than 300 KB. From Google. Widely used (Maven lists over
23000 other software depending on it) so not likely to go away.

Arne
Dennis Boone
2024-08-09 14:56:01 UTC
Permalink
Post by Arne Vajhøj
GSON is less than 300 KB. From Google. Widely used (Maven lists over
23000 other software depending on it) so not likely to go away.
https://killedbygoogle.com/

De
Arne Vajhøj
2024-08-09 15:21:00 UTC
Permalink
Post by Dennis Boone
Post by Arne Vajhøj
GSON is less than 300 KB. From Google. Widely used (Maven lists over
23000 other software depending on it) so not likely to go away.
https://killedbygoogle.com/
Google could ditch it. It has never been an official
supported Google product.

But it is open source under Apache license.

https://github.com/google/gson

Being open source does not by magic produce maintainers.

But:
* with 23000 projects depending on it
* no external dependencies
* no need for huge enhancements (JSON is JSON)
then it seems like a pretty safe bet.

Arne
Dennis Boone
2024-08-09 18:48:01 UTC
Permalink
Post by Arne Vajhøj
* with 23000 projects depending on it
* no external dependencies
* no need for huge enhancements (JSON is JSON)
then it seems like a pretty safe bet.
I _was_ mostly being hyperbolic, but the fact remains that big G
will cheerfully kill off services with (merely) millions of users.

De
Lawrence D'Oliveiro
2024-08-09 23:27:09 UTC
Permalink
I _was_ mostly being hyperbolic, but the fact remains that big G will
cheerfully kill off services with (merely) millions of users.
True of any proprietary vendor. When Windows 98 was abandoned by
Microsoft, I recall a report that it still had something like 40 million
users.

Arne Vajhøj
2024-08-08 00:38:02 UTC
Permalink
Post by Lawrence D'Oliveiro
Trying to do select/poll? There’s something like 4 different classes and I
don’t know how many methods involved.
There are several ways to do that in Java:
* java.nio
* Netty
* RxJava
* ...

All of them require a bit of documentation reading.

But so does the same problem in languages like
C# and C.

And the typical Java application works at a higher
level - it asks some framework to listen at a given
port and call some code to process requests.

SOAP example:

Endpoint.publish("http://localhost:8080/test/Test", new Test());

XML-RPC example:

WebServer srv = new WebServer(8001);
XmlRpcServer xmlrpc = srv.getXmlRpcServer();
srv.start();
PropertyHandlerMapping phm = new PropertyHandlerMapping();
phm.addHandler("Test", Test.class);
xmlrpc.setHandlerMapping(phm);

RestFul example:

Server server = new Server(PORT);
ServletContextHandler ctx = new
ServletContextHandler(ServletContextHandler.NO_SESSIONS);
ctx.setContextPath(CONTEXT);
server.setHandler(ctx);
ServletHolder srvlet = ctx.addServlet(ServletContainer.class, API);
srvlet.setInitOrder(1);

srvlet.setInitParameter("com.sun.jersey.config.property.packages",
"server");

srvlet.setInitParameter("com.sun.jersey.api.json.POJOMappingFeature",
"true");
server.start();
server.join();

Thrift:

TServerTransport transport = new TServerSocket(PORT);
Test.Iface handler = new TestHandler();
TServer server = new TThreadPoolServer(new
TThreadPoolServer.Args(transport).processor(new
Test.Processor<Test.Iface>(handler)));
server.serve();

GRPC:

Server srv = ServerBuilder.forPort(JAVA_PORT).addService(new
TestServer()).build();
srv.start();

Arne
Lawrence D'Oliveiro
2024-08-08 01:26:20 UTC
Permalink
Post by Arne Vajhøj
Post by Lawrence D'Oliveiro
Trying to do select/poll? There’s something like 4 different classes
and I don’t know how many methods involved.
* java.nio
* Netty
* RxJava
* ...
All of them require a bit of documentation reading.
But so does the same problem in languages like C# and C.
The POSIX calls are quite straightforward
<https://manpages.debian.org/2/poll.2.en.html>.
Post by Arne Vajhøj
And the typical Java application works at a higher level - it asks some
framework to listen at a given port and call some code to process
requests.
So does Python. Yet it can do it much more simply
<https://docs.python.org/3/library/select.html> -- even the asyncio
framework makes it easy to watch a file descriptor
<https://docs.python.org/3/library/asyncio-eventloop.html#watching-file-descriptors>
Arne Vajhøj
2024-08-05 01:23:09 UTC
Permalink
Post by Dan Cross
Post by Arne Vajhøj
Post by Dan Cross
Post by Scott Dorsey
Post by Uli Bellgardt
$ type zzz.pas
program z(input,output);
var
x : f_float;
This seems very strange to me... Pascal isn't supposed to have such
strong typing, is it? I don't remember ever having to manually coerce
anything. Or is f_float sufficiently different from a normal float?
Just to touch on the Pascal point itself, one of that language's
hallmarks is almost excessive rigidity in how it treats types.
Ada is even more strict.
Rust even more so.
There may be different definitions of strict.

But my take (apropos arrays) is:

level 0 - languages that use types of wider range than
array size as array index and do not check
whether an index is in range at runtime so
that programming errors with bad array indexes
result in unpredictable behavior at runtime

level 1 - languages that use types of wider range than
array size as array index and do check
whether an index is in range at runtime so
that programming errors with bad array indexes
result in an immediate exception

level 1.1 - languages that allow use of types of exact range of
array size as array index, but do not restrict
array index to that type and do check whether an
index is in range at runtime so that programming
errors with bad array indexes result in an immediate
exception

level 2.0 - languages that allow use of types of exact range of
array size as array index, and do restrict
array index to that type so that programming
errors with bad array indexes result in a compile error

Ada is level 2.0 (if using type and not subtype for array index).

Arne
Dan Cross
2024-08-05 01:59:21 UTC
Permalink
Post by Arne Vajhøj
Post by Dan Cross
Post by Arne Vajhøj
Post by Dan Cross
Post by Scott Dorsey
Post by Uli Bellgardt
$ type zzz.pas
program z(input,output);
var
x : f_float;
This seems very strange to me... Pascal isn't supposed to have such
strong typing, is it? I don't remember ever having to manually coerce
anything. Or is f_float sufficiently different from a normal float?
Just to touch on the Pascal point itself, one of that language's
hallmarks is almost excessive rigidity in how it treats types.
Ada is even more strict.
Rust even more so.
There may be different definitions of strict.
You should spend some more time learning, less writing.
Perhaps read up on programming languages.

- Dan C.
John Reagan
2024-08-04 21:53:32 UTC
Permalink
Post by Scott Dorsey
Post by Uli Bellgardt
$ type zzz.pas
program z(input,output);
var
x : f_float;
This seems very strange to me... Pascal isn't supposed to have such
strong typing, is it? I don't remember ever having to manually coerce
anything. Or is f_float sufficiently different from a normal float?
--scott
Why didn't I do this?

I did think about it, but what about more complicated expression.

x := 1.5 * 1.5;

Is that multiply an IEEE S_float multiply or VAX F_float multiply?
Logically, it would have been an IEEE S_float multiply and then
converted to VAX F_float. I didn't think it was a problem that needed
to be solved.

Pascal was the first to let you mix both kinds of floats in the same
module (or so I think). The %F_FLOAT was designed to solve the LIB$WAIT
issue when IEEE floating was enabled (yes, I know about the extra
argument to LIB$WAIT).
Arne Vajhøj
2024-08-04 23:45:19 UTC
Permalink
Post by John Reagan
Why didn't I do this?
I did think about it, but what about more complicated expression.
x := 1.5 * 1.5;
Is that multiply an IEEE S_float multiply or VAX F_float multiply?
Logically, it would have been an IEEE S_float multiply and then
converted to VAX F_float.  I didn't think it was a problem that needed
to be solved.
I was sort of expecting literals to be of the type determined by
suffix and compiler switch and that mixed expressions would be
converted similar to various other mixed expressions.

That was not the case.

Probably not worth spending time on "fixing". It must be
an extremely rare case.

Arne
Arne Vajhøj
2024-08-07 00:38:19 UTC
Permalink
Post by Arne Vajhøj
Post by John Reagan
Why didn't I do this?
I did think about it, but what about more complicated expression.
x := 1.5 * 1.5;
Is that multiply an IEEE S_float multiply or VAX F_float multiply?
Logically, it would have been an IEEE S_float multiply and then
converted to VAX F_float.  I didn't think it was a problem that needed
to be solved.
I was sort of expecting literals to be of the type determined by
suffix and compiler switch and that mixed expressions would be
converted similar to various other mixed expressions.
That was not the case.
Probably not worth spending time on "fixing". It must be
an extremely rare case.
And in case someone wonder.

I was trying to have one file instead of three files to test
all FP's.

module demov(input, output);

[global]
function f_check(var v : f_float) : integer;

begin
v := v + %f_float 0.001;
f_check := 1;
end;

[global]
function d_check(var v : d_float) : integer;

begin
v := v + %d_float 0.001;
d_check := 1;
end;

[global]
function g_check(var v : g_float) : integer;

begin
v := v + %g_float 0.001;
g_check := 1;
end;

[global]
function s_check(var v : s_float) : integer;

begin
v := v + 0.001;
s_check := 1;
end;

[global]
function t_check(var v : t_float) : integer;

begin
v := v + 0.001;
t_check := 1;
end;

end.

:-)

Arne
Arne Vajhøj
2024-08-03 18:33:31 UTC
Permalink
Post by Uli Bellgardt
$ type zzz.pas
program z(input,output);
var
   x : f_float;
begin
   x := %f_float 1.5;
   writeln(x);
end.
$ pas zzz
$ link zzz
$ run zzz
 1.50000E+00
I would never have guessed.

Now that you have told me then it is of course easy to find
in the manual.

Columbus egg.

Thanks.

Arne
Loading...