comp.lang.ada
 help / color / mirror / Atom feed
From: "G.B." <bauhaus@futureapps.invalid>
Subject: Re: Build language with weak typing, then add scaffolding later to strengthen it?
Date: Fri, 22 May 2015 16:25:44 +0200
Date: 2015-05-22T16:25:44+02:00	[thread overview]
Message-ID: <mjne73$tjn$1@dont-email.me> (raw)
In-Reply-To: <mjn90s$9av$1@dont-email.me>

On 22.05.15 14:57, J-P. Rosen wrote:
> Le 22/05/2015 13:29, kalvin.news@gmail.com a écrit :
>> Even C could be made more robust, if simple type checking is
>> performed at compile time. For example,
>>
>> typedef int apples;
>>
>> typedef int oranges;
>>
>> apples a = 5; oranges o = a;
>>
>> should generate type check error as the types are definitely
>> different types. Also, assigning enums to ints and ints to enums
>> should be considered illegal.
>>
> I don't agree. C is a low level language, and good at that. Its types
> are those of the  machine: bytes and addresses, the rest is a (small
> quantity of) syntactic sugar.

Not sure this description of what C is in the eye of
an Adaist will win an argument; first, it is not exactly
right. (If myths say that int was influenced by PDP hardware
40 years ago, this doesn't seem to reflect C compilers in use
today, or yesterday.)

While the C type int is defined by the C standard,
one needs to consult the implementation's docs to
learn the specifics of int for a given implementation.

Same for Ada!

There would have been an opportunity to point out
the extended possibilities that Ada offers for expressing
expectations on types. But

   LS : String(1 .. 100_000);

is not defined by the Ada LRM as an unequivocally valid
piece of Ada source text, since Positive, and therefore
String, are only defined to much the same extent that C's
int is defined by C.

OTOH, what happens if I'd write  *(p + 100000-1) in a
C program?

Then, the C standard is explicit about what a byte is.
A C int cannot be expressed as bytes of C. Nor is the
behavior of int objects in borderline situations devoid
of context in the standard.

There also is no forced relationship of machine words and
int for a C implementation: 32 bits on a 64 bit architecture
is a valid choice. But that _is_ a source of trouble!

The issues are elsewhere, and it seems like a good opportunity
to show that, with Ada, there is actually more in the hands
of a programmer to address issues that cannot be addressed in
portable C source text; e.g., reactions to overflow.

C is in many ways as strongly typed as Ada, just not everywhere,
and that's worth pointing out, specifically addressing the typical
problems that C programs tend to run into.

C, in addition, has neither subtype constraints, nor derived types,
nor language-defined representation expressions etc.. But is _does_
have named type equivalence:

typedef struct apples { int amount; } Apples;
typedef struct oranges { int amount; } Oranges;

Oranges f() {
   Apples a = { .amount = 5 };

   return a;
}

The definition triggers a compile time error: it is nor permissible
to return a structurally equivalent struct apples when instead
a struct oranges was named as the return type in f's profile.

If the error is corrected, then the code produced, even when
just modest optimization is requested, will be the same as if
only a scalar type had been used.

That is not to say that I'd expect C programmers to avoid bare int.
Nor that the "solution" looks attractive. But it does confirm
that to say that C is a weakly typed _language_ will be ignored
by any C programmer in charge. Doing so falls short of being
an argument.

  parent reply	other threads:[~2015-05-22 14:25 UTC|newest]

Thread overview: 111+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-05-21 19:11 Build language with weak typing, then add scaffolding later to strengthen it? Nasser M. Abbasi
2015-05-21 19:29 ` AdaMagica
2015-05-22  7:27   ` Dmitry A. Kazakov
2015-05-22  7:42 ` Georg Bauhaus
2015-05-22  8:54   ` Nasser M. Abbasi
2015-05-22 11:29 ` kalvin.news
2015-05-22 12:57   ` J-P. Rosen
2015-05-22 14:01     ` kalvin.news
2015-05-22 14:34       ` kalvin.news
2015-05-23 11:09         ` Peter Chapin
2015-05-22 15:37       ` J-P. Rosen
2015-05-22 16:29         ` kalvin.news
2015-05-22 17:39           ` Simon Clubley
2015-05-22 17:51             ` kalvin.news
2015-05-22 19:41               ` J-P. Rosen
2015-05-22 20:04                 ` kalvin.news
2015-05-22 20:32                   ` Jeffrey R. Carter
2015-05-22 21:22                     ` kalvin.news
2015-05-23 11:14                     ` Peter Chapin
2015-05-23 12:42                       ` Jeffrey R. Carter
2015-05-23 17:48                         ` Simon Wright
2015-05-25  8:34                           ` Pascal Obry
2015-05-25 10:22                             ` Simon Wright
2015-05-25 18:12                               ` Georg Bauhaus
2015-05-22 20:39                   ` jan.de.kruyf
2015-05-28 22:33                     ` Randy Brukardt
2015-05-29  6:56                       ` jan.de.kruyf
2015-05-23 12:40                   ` Georg Bauhaus
2015-05-25  7:14                     ` jan.de.kruyf
2015-05-25 12:26                       ` Georg Bauhaus
2015-05-25 18:44                       ` Shark8
2015-05-25 19:54                         ` jan.de.kruyf
2015-05-25 21:25                           ` Shark8
2015-05-26  7:46                           ` Georg Bauhaus
2015-05-26  8:12                           ` Georg Bauhaus
2015-05-25 20:01                         ` Nasser M. Abbasi
2015-05-25 20:04                           ` Nasser M. Abbasi
2015-05-25 20:37                             ` jan.de.kruyf
2015-05-26  7:52                               ` Jacob Sparre Andersen
2015-05-26 11:43                                 ` jan.de.kruyf
2015-05-26 15:38                                   ` jan.de.kruyf
2015-05-28 23:39                                   ` Randy Brukardt
2015-05-29  8:51                                     ` Stefan.Lucks
2015-05-29 18:04                                       ` Jeffrey R. Carter
2015-05-29 21:51                                       ` Randy Brukardt
2015-05-30 10:28                                         ` jan.de.kruyf
2015-05-30 11:12                                           ` Dmitry A. Kazakov
2015-05-30 13:21                                             ` jan.de.kruyf
2015-05-30 15:00                                               ` Simon Clubley
2015-05-30 18:40                                                 ` jan.de.kruyf
2015-05-30 16:40                                               ` Dmitry A. Kazakov
2015-05-30 20:52                                                 ` jan.de.kruyf
2015-05-31  8:31                                                   ` Nasser M. Abbasi
2015-05-31  8:52                                                   ` Dmitry A. Kazakov
2015-06-04 15:31                                                     ` jan.de.kruyf
2015-06-04 17:23                                                       ` Dmitry A. Kazakov
2015-06-04 20:14                                                         ` Shark8
2015-06-04 23:12                                                           ` Nasser M. Abbasi
2015-06-01 21:36                                                 ` Randy Brukardt
2015-06-04 15:22                                                   ` jan.de.kruyf
2015-05-27 13:41                                 ` jan.de.kruyf
2015-05-25 23:05                             ` Peter Chapin
2015-05-26  8:01                               ` Sylvain Laperche
2015-05-26  8:20                                 ` Georg Bauhaus
2015-05-26  8:49                                 ` J-P. Rosen
2015-05-26 12:36                                   ` Simon Clubley
2015-05-26 13:39                                     ` J-P. Rosen
2015-05-26 14:21                                       ` Dmitry A. Kazakov
2015-05-26 16:19                                       ` Shark8
2015-05-26 20:51                                         ` J-P. Rosen
2015-05-26 17:11                                   ` Jeffrey R. Carter
2015-05-28 23:49                                     ` Randy Brukardt
2015-05-29 21:54                                       ` Randy Brukardt
2015-05-29 22:32                                         ` Jeffrey R. Carter
2015-05-26  8:17                               ` Georg Bauhaus
2015-05-28 22:46                       ` Randy Brukardt
2015-05-28 23:18                         ` Nasser M. Abbasi
2015-05-29 21:27                           ` Randy Brukardt
2015-05-29  7:55                         ` jan.de.kruyf
2015-05-29  9:27                           ` Simon Wright
2015-05-29 10:23                             ` jan.de.kruyf
2015-05-29 12:01                               ` G.B.
2015-05-29 13:43                                 ` jan.de.kruyf
2015-05-29 15:32                             ` Simon Wright
2015-05-29 15:57                               ` jan.de.kruyf
2015-05-29  9:31                         ` Jacob Sparre Andersen
2015-05-29 10:37                           ` jan.de.kruyf
2015-05-29 10:56                           ` Björn Lundin
2015-05-29 12:03                             ` Peter Chapin
2015-05-29 21:00                               ` Shark8
2015-05-29 20:57                           ` Shark8
2015-05-29 21:36                             ` Randy Brukardt
2015-06-01 22:20                               ` Shark8
2015-05-29 21:45                           ` Randy Brukardt
2015-05-29 23:12                             ` Peter Chapin
2015-05-30  9:10                               ` Georg Bauhaus
2015-05-23 13:01                 ` Luke A. Guest
2015-05-22 17:57             ` Simon Wright
2015-05-22 18:31               ` jan.de.kruyf
2015-05-22 14:03     ` jan.de.kruyf
2015-05-22 15:21       ` David Botton
2015-05-22 15:23         ` jan.de.kruyf
2015-05-22 15:31       ` Bob Duff
2015-05-22 15:48         ` jan.de.kruyf
2015-05-22 14:25     ` G.B. [this message]
2015-05-22 15:04     ` Bill White
2015-05-22 15:28     ` Bob Duff
2015-05-22 17:46       ` Simon Clubley
2015-05-22 18:16         ` jan.de.kruyf
2015-05-22 19:01           ` Simon Wright
2015-05-22 19:41             ` jan.de.kruyf
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox