• Simple Pascal question

    From =?UTF-8?Q?Arne_Vajh=C3=B8j?=@21:1/5 to All on Thu Aug 1 15:42:10 2024
    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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Uli Bellgardt@21:1/5 to All on Fri Aug 2 06:25:26 2024
    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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Scott Dorsey@21:1/5 to UliBellgardtsSpamSink@online.de on Sat Aug 3 17:32:16 2024
    In article <v8hn3m$3aviu$1@gwaiyur.mb-net.net>,
    Uli Bellgardt <UliBellgardtsSpamSink@online.de> wrote:
    The value 1.5 should be an f_float value as well:

    $ 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."

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From =?UTF-8?Q?Arne_Vajh=C3=B8j?=@21:1/5 to Scott Dorsey on Sat Aug 3 14:40:32 2024
    On 8/3/2024 1:32 PM, Scott Dorsey wrote:
    In article <v8hn3m$3aviu$1@gwaiyur.mb-net.net>,
    Uli Bellgardt <UliBellgardtsSpamSink@online.de> wrote:
    The value 1.5 should be an f_float value as well:

    $ 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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From =?UTF-8?Q?Arne_Vajh=C3=B8j?=@21:1/5 to Uli Bellgardt on Sat Aug 3 14:33:31 2024
    On 8/2/2024 12:25 AM, Uli Bellgardt wrote:
    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

    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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Dan Cross@21:1/5 to Scott Dorsey on Sun Aug 4 12:22:01 2024
    In article <v8lpj0$ems$1@panix2.panix.com>,
    Scott Dorsey <kludge@panix.com> wrote:
    In article <v8hn3m$3aviu$1@gwaiyur.mb-net.net>,
    Uli Bellgardt <UliBellgardtsSpamSink@online.de> wrote:
    The value 1.5 should be an f_float value as well:

    $ 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.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From =?UTF-8?Q?Arne_Vajh=C3=B8j?=@21:1/5 to Dan Cross on Sun Aug 4 10:51:20 2024
    On 8/4/2024 8:22 AM, Dan Cross wrote:
    In article <v8lpj0$ems$1@panix2.panix.com>,
    Scott Dorsey <kludge@panix.com> wrote:
    In article <v8hn3m$3aviu$1@gwaiyur.mb-net.net>,
    Uli Bellgardt <UliBellgardtsSpamSink@online.de> wrote:
    The value 1.5 should be an f_float value as well:

    $ 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.

    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

    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.

    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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From John Reagan@21:1/5 to Scott Dorsey on Sun Aug 4 17:53:32 2024
    On 8/3/2024 1:32 PM, Scott Dorsey wrote:
    In article <v8hn3m$3aviu$1@gwaiyur.mb-net.net>,
    Uli Bellgardt <UliBellgardtsSpamSink@online.de> wrote:
    The value 1.5 should be an f_float value as well:

    $ 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).

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Lawrence D'Oliveiro@21:1/5 to All on Sun Aug 4 22:19:03 2024
    On Sun, 4 Aug 2024 10:51:20 -0400, Arne Vajhøj wrote:

    On 8/4/2024 8:22 AM, Dan Cross wrote:

    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.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From =?UTF-8?Q?Arne_Vajh=C3=B8j?=@21:1/5 to John Reagan on Sun Aug 4 19:45:19 2024
    On 8/4/2024 5:53 PM, John Reagan wrote:
    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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From =?UTF-8?Q?Arne_Vajh=C3=B8j?=@21:1/5 to Lawrence D'Oliveiro on Sun Aug 4 19:55:02 2024
    On 8/4/2024 6:19 PM, Lawrence D'Oliveiro wrote:
    On Sun, 4 Aug 2024 10:51:20 -0400, Arne Vajhøj wrote:
    On 8/4/2024 8:22 AM, Dan Cross wrote:
    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..

    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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Dan Cross@21:1/5 to arne@vajhoej.dk on Mon Aug 5 00:09:48 2024
    In article <v8o4h8$2ut3$1@dont-email.me>,
    Arne Vajhøj <arne@vajhoej.dk> wrote:
    On 8/4/2024 8:22 AM, Dan Cross wrote:
    In article <v8lpj0$ems$1@panix2.panix.com>,
    Scott Dorsey <kludge@panix.com> wrote:
    In article <v8hn3m$3aviu$1@gwaiyur.mb-net.net>,
    Uli Bellgardt <UliBellgardtsSpamSink@online.de> wrote:
    The value 1.5 should be an f_float value as well:

    $ 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.

    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.

    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.

    [snip]
    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.

    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.

    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);
    }
    }

    Java arrays are more like the aforementioned slices.

    - Dan C.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From =?UTF-8?Q?Arne_Vajh=C3=B8j?=@21:1/5 to Dan Cross on Sun Aug 4 21:00:35 2024
    On 8/4/2024 8:09 PM, Dan Cross wrote:
    In article <v8o4h8$2ut3$1@dont-email.me>,
    Arne Vajhøj <arne@vajhoej.dk> wrote:
    On 8/4/2024 8:22 AM, Dan Cross wrote:
    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.

    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:

    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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Dan Cross@21:1/5 to arne@vajhoej.dk on Mon Aug 5 01:58:04 2024
    In article <v8p87j$9ptm$3@dont-email.me>,
    Arne Vajhøj <arne@vajhoej.dk> wrote:
    On 8/4/2024 8:09 PM, Dan Cross wrote:
    In article <v8o4h8$2ut3$1@dont-email.me>,
    Arne Vajhøj <arne@vajhoej.dk> wrote:
    On 8/4/2024 8:22 AM, Dan Cross wrote:
    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.

    But there are still languages like C#, Scala and Kotlin.

    Or Rust, Go, Zig, etc.

    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.

    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);
    }
    }

    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.

    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.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Dan Cross@21:1/5 to arne@vajhoej.dk on Mon Aug 5 01:59:21 2024
    In article <v8p9ht$9ptm$4@dont-email.me>,
    Arne Vajhøj <arne@vajhoej.dk> wrote:
    On 8/4/2024 8:09 PM, Dan Cross wrote:
    In article <v8o4h8$2ut3$1@dont-email.me>,
    Arne Vajhøj <arne@vajhoej.dk> wrote:
    On 8/4/2024 8:22 AM, Dan Cross wrote:
    In article <v8lpj0$ems$1@panix2.panix.com>,
    Scott Dorsey <kludge@panix.com> wrote:
    In article <v8hn3m$3aviu$1@gwaiyur.mb-net.net>,
    Uli Bellgardt <UliBellgardtsSpamSink@online.de> wrote:
    The value 1.5 should be an f_float value as well:

    $ 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:

    You should spend some more time learning, less writing.
    Perhaps read up on programming languages.

    - Dan C.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From =?UTF-8?Q?Arne_Vajh=C3=B8j?=@21:1/5 to Dan Cross on Sun Aug 4 21:23:09 2024
    On 8/4/2024 8:09 PM, Dan Cross wrote:
    In article <v8o4h8$2ut3$1@dont-email.me>,
    Arne Vajhøj <arne@vajhoej.dk> wrote:
    On 8/4/2024 8:22 AM, Dan Cross wrote:
    In article <v8lpj0$ems$1@panix2.panix.com>,
    Scott Dorsey <kludge@panix.com> wrote:
    In article <v8hn3m$3aviu$1@gwaiyur.mb-net.net>,
    Uli Bellgardt <UliBellgardtsSpamSink@online.de> wrote:
    The value 1.5 should be an f_float value as well:

    $ 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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Lawrence D'Oliveiro@21:1/5 to All on Mon Aug 5 02:41:44 2024
    On Sun, 4 Aug 2024 19:55:02 -0400, Arne Vajhøj wrote:

    On 8/4/2024 6:19 PM, Lawrence D'Oliveiro wrote:

    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.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Lawrence D'Oliveiro@21:1/5 to All on Mon Aug 5 02:44:19 2024
    On Sun, 4 Aug 2024 21:00:35 -0400, Arne Vajhøj wrote:

    In article <v8o4h8$2ut3$1@dont-email.me>,
    Arne Vajhøj <arne@vajhoej.dk> wrote:

    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.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From John Reagan@21:1/5 to Lawrence D'Oliveiro on Mon Aug 5 00:18:32 2024
    On 8/4/2024 6:19 PM, Lawrence D'Oliveiro wrote:
    On Sun, 4 Aug 2024 10:51:20 -0400, Arne Vajhøj wrote:

    On 8/4/2024 8:22 AM, Dan Cross wrote:

    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.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Michael S@21:1/5 to arne@vajhoej.dk on Mon Aug 5 15:34:49 2024
    On Sun, 4 Aug 2024 21:00:35 -0400
    Arne Vajhøj <arne@vajhoej.dk> wrote:

    On 8/4/2024 8:09 PM, Dan Cross wrote:
    In article <v8o4h8$2ut3$1@dont-email.me>,
    Arne Vajhøj <arne@vajhoej.dk> wrote:
    On 8/4/2024 8:22 AM, Dan Cross wrote:
    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.

    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:

    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".

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

    Arne




    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Lawrence D'Oliveiro@21:1/5 to Michael S on Mon Aug 5 21:29:26 2024
    On Mon, 5 Aug 2024 15:34:49 +0300, Michael S wrote:

    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.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From =?UTF-8?Q?Arne_Vajh=C3=B8j?=@21:1/5 to Michael S on Tue Aug 6 19:57:50 2024
    On 8/5/2024 8:34 AM, Michael S wrote:
    On Sun, 4 Aug 2024 21:00:35 -0400
    Arne Vajhøj <arne@vajhoej.dk> wrote:
    On 8/4/2024 8:09 PM, Dan Cross wrote:
    In article <v8o4h8$2ut3$1@dont-email.me>,
    Arne Vajhøj <arne@vajhoej.dk> wrote:
    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);
    }
    }

    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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From =?UTF-8?Q?Arne_Vajh=C3=B8j?=@21:1/5 to Lawrence D'Oliveiro on Tue Aug 6 20:13:07 2024
    On 8/5/2024 5:29 PM, Lawrence D'Oliveiro wrote:
    On Mon, 5 Aug 2024 15:34:49 +0300, Michael S wrote:
    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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From =?UTF-8?Q?Arne_Vajh=C3=B8j?=@21:1/5 to Dan Cross on Tue Aug 6 19:46:24 2024
    On 8/4/2024 9:58 PM, Dan Cross wrote:
    In article <v8p87j$9ptm$3@dont-email.me>,
    Arne Vajhøj <arne@vajhoej.dk> wrote:
    On 8/4/2024 8:09 PM, Dan Cross wrote:
    In article <v8o4h8$2ut3$1@dont-email.me>,
    Arne Vajhøj <arne@vajhoej.dk> wrote:
    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);
    }
    }

    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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From =?UTF-8?Q?Arne_Vajh=C3=B8j?=@21:1/5 to All on Tue Aug 6 20:27:53 2024
    On 8/6/2024 7:57 PM, Arne Vajhøj wrote:
    On 8/5/2024 8:34 AM, Michael S wrote:
    On Sun, 4 Aug 2024 21:00:35 -0400
    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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From =?UTF-8?Q?Arne_Vajh=C3=B8j?=@21:1/5 to All on Tue Aug 6 20:38:19 2024
    On 8/4/2024 7:45 PM, Arne Vajhøj wrote:
    On 8/4/2024 5:53 PM, John Reagan wrote:
    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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From =?UTF-8?Q?Arne_Vajh=C3=B8j?=@21:1/5 to All on Wed Aug 7 16:12:48 2024
    On 8/4/2024 9:00 PM, Arne Vajhøj wrote:
    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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Lawrence D'Oliveiro@21:1/5 to All on Wed Aug 7 21:35:23 2024
    On Wed, 7 Aug 2024 16:12:48 -0400, Arne Vajhøj wrote:

    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.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From =?UTF-8?Q?Arne_Vajh=C3=B8j?=@21:1/5 to Lawrence D'Oliveiro on Wed Aug 7 20:11:21 2024
    On 8/7/2024 5:35 PM, Lawrence D'Oliveiro wrote:
    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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From =?UTF-8?Q?Arne_Vajh=C3=B8j?=@21:1/5 to Lawrence D'Oliveiro on Wed Aug 7 20:38:02 2024
    On 8/7/2024 5:35 PM, Lawrence D'Oliveiro wrote:
    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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Lawrence D'Oliveiro@21:1/5 to All on Thu Aug 8 01:26:20 2024
    On Wed, 7 Aug 2024 20:38:02 -0400, Arne Vajhøj wrote:

    On 8/7/2024 5:35 PM, Lawrence D'Oliveiro wrote:

    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.

    The POSIX calls are quite straightforward <https://manpages.debian.org/2/poll.2.en.html>.

    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>

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Dan Cross@21:1/5 to arne@vajhoej.dk on Thu Aug 8 05:33:01 2024
    In article <v8uckf$1uf43$1@dont-email.me>,
    Arne Vajhøj <arne@vajhoej.dk> wrote:
    On 8/4/2024 9:58 PM, Dan Cross wrote:
    In article <v8p87j$9ptm$3@dont-email.me>,
    Arne Vajhøj <arne@vajhoej.dk> wrote:
    On 8/4/2024 8:09 PM, Dan Cross wrote:
    In article <v8o4h8$2ut3$1@dont-email.me>,
    Arne Vajhøj <arne@vajhoej.dk> wrote:
    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);
    }
    }

    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.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Simon Clubley@21:1/5 to arne@vajhoej.dk on Thu Aug 8 12:13:04 2024
    On 2024-08-07, Arne Vajhj <arne@vajhoej.dk> wrote:
    On 8/7/2024 5:35 PM, Lawrence D'Oliveiro wrote:
    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, clubley@remove_me.eisner.decus.org-Earth.UFP
    Walking destinations on a map are further away than they appear.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From =?UTF-8?Q?Arne_Vajh=C3=B8j?=@21:1/5 to Simon Clubley on Thu Aug 8 08:57:20 2024
    On 8/8/2024 8:13 AM, Simon Clubley wrote:
    On 2024-08-07, Arne Vajhøj <arne@vajhoej.dk> wrote:
    On 8/7/2024 5:35 PM, Lawrence D'Oliveiro wrote:
    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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From =?UTF-8?Q?Arne_Vajh=C3=B8j?=@21:1/5 to All on Thu Aug 8 09:00:25 2024
    On 8/8/2024 8:57 AM, Arne Vajhøj wrote:
    On 8/8/2024 8:13 AM, Simon Clubley wrote:
    On 2024-08-07, Arne Vajhøj <arne@vajhoej.dk> wrote:
    On 8/7/2024 5:35 PM, Lawrence D'Oliveiro wrote:
    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.

    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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Simon Clubley@21:1/5 to arne@vajhoej.dk on Fri Aug 9 12:47:41 2024
    On 2024-08-08, Arne Vajhj <arne@vajhoej.dk> wrote:
    On 8/8/2024 8:13 AM, Simon Clubley wrote:
    On 2024-08-07, Arne Vajhj <arne@vajhoej.dk> wrote:
    On 8/7/2024 5:35 PM, Lawrence D'Oliveiro wrote:
    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.

    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.


    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, clubley@remove_me.eisner.decus.org-Earth.UFP
    Walking destinations on a map are further away than they appear.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Dennis Boone@21:1/5 to All on Fri Aug 9 14:56:01 2024
    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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From =?UTF-8?Q?Arne_Vajh=C3=B8j?=@21:1/5 to Simon Clubley on Fri Aug 9 10:25:28 2024
    On 8/9/2024 8:47 AM, Simon Clubley wrote:
    On 2024-08-08, Arne Vajhøj <arne@vajhoej.dk> wrote:
    On 8/8/2024 8:13 AM, Simon Clubley wrote:
    On 2024-08-07, Arne Vajhøj <arne@vajhoej.dk> wrote:
    On 8/7/2024 5:35 PM, Lawrence D'Oliveiro wrote:
    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.

    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.

    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.

    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

    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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From =?UTF-8?Q?Arne_Vajh=C3=B8j?=@21:1/5 to Dennis Boone on Fri Aug 9 11:21:00 2024
    On 8/9/2024 10:56 AM, Dennis Boone wrote:
    > 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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Dennis Boone@21:1/5 to All on Fri Aug 9 18:48:01 2024
    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.

    I _was_ mostly being hyperbolic, but the fact remains that big G
    will cheerfully kill off services with (merely) millions of users.

    De

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Lawrence D'Oliveiro@21:1/5 to Dennis Boone on Fri Aug 9 23:27:09 2024
    On Fri, 09 Aug 2024 18:48:01 +0000, Dennis Boone wrote:

    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.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)