comp.lang.ada
 help / color / mirror / Atom feed
From: kalvin.news@gmail.com
Subject: Re: Build language with weak typing, then add scaffolding later to strengthen it?
Date: Fri, 22 May 2015 09:29:11 -0700 (PDT)
Date: 2015-05-22T09:29:11-07:00	[thread overview]
Message-ID: <ad8483c7-8f3c-4469-9079-a97ca3abaf27@googlegroups.com> (raw)
In-Reply-To: <mjnieh$ejn$1@dont-email.me>

perjantai 22. toukokuuta 2015 18.37.59 UTC+3 J-P. Rosen kirjoitti:
> Le 22/05/2015 16:01, kalvin-nospamhere-.news@gmail.com a écrit :
> > 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.
> >> 
> >> If you need strong typing, use a strongly typed language. But don't
> >> blame C for not being strongly typed, it was simply not part of the
> >> requirements.
> >> 
> (Making my point clearer after various reactions).
> 
> Languages have history; they stemmed from a need for solving a certain
> class of problems. Then people tend to use them for different purposes.
> My point is that each language should be used for what it's good at.
> 
> C was created for writing an operating system, and it's initial
> requirement were to be a "portable assembly language". At that level,
> there is no place for typing: a machine word is what you make of it,
> there is no difference between a float, an int, or whatever. I certainly
> wouldn't object to writing a device driver in C.
> 
> Now, it's true that people use it to write higher level applications.
> That doesn't make the language higher level. After all, when I started
> programming, almost any serious application was written in assembly.
> 
> I have seen people writing databases in APL, real-time programs in Java,
> high-reliability applications in C, etc. My plea is "use the right tool
> for the job". I wouldn't advocate Ada for "throw-away" programs with a
> life-time of one day. But when it comes to safety-critical and/or
> long-lived and/or high reliability and/or etc...
> 
> -- 
> J-P. Rosen
> Adalog
> 2 rue du Docteur Lombard, 92441 Issy-les-Moulineaux CEDEX
> Tel: +33 1 45 29 21 52, Fax: +33 1 45 29 25 00
> http://www.adalog.fr

My point here is that although an int is an int, an int in one context may be totally different from another int, although both entities are of type int.

For example, a low-level harddisk device driver might contain declarations like this:

int cylinder = 1;
int head = 2;
int sector = 3;

So, it is quite easy to do something stupid like this:

head = sector;

The compiler is happy as we assign an int to another int, but clearily we are assigning apples to oranges, which is not something that we typically want to do. However, we have not coveyed any information about our intentions here, and all ints are treated equally although clearily the ints contain different kind of integer values.

Of course, one should declare distinct types for the different entities holding information about the cylinder, head and sector. This would also document the code better and convey more of the programmer's intent: 

typedef int Cylinder;
typedef int Head;
typedef int Sector;

Cylinder cylinder = 1;
Head head = 2;
Sector sector = 3;

In C/C++ it is still allowed to do this stupid assignment without any compiler warning or error whatsoever:

head = sector;

In my opinion, this should not be allowed or at least the compiler should generate a big loud warning, as we were stating specifically that the variable head is of type Head and the variable cylinder is of type Cylinder. The programmer has stated a specific intentent to declare distinct types for the Cylinder, Head and Sector and they should not be intermixed unless they are specifically typecasted to another type.

Ps. Creating specific type declarations like:

typedef int Sector;

would make porting a bit easier should the maximum allowed sector count be increased to more than 65535 and an int is only 16 bits:

typedef long int Sector;

  reply	other threads:[~2015-05-22 16:29 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 [this message]
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.
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