From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-0.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM, FREEMAIL_REPLY autolearn=no autolearn_force=no version=3.4.4 X-Received: by 10.42.149.6 with SMTP id t6mr11438490icv.25.1432312151576; Fri, 22 May 2015 09:29:11 -0700 (PDT) X-Received: by 10.140.100.136 with SMTP id s8mr138032qge.2.1432312151550; Fri, 22 May 2015 09:29:11 -0700 (PDT) Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!mx02.eternal-september.org!feeder.eternal-september.org!usenet.blueworldhosting.com!feeder01.blueworldhosting.com!peer01.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!j8no7960270igd.0!news-out.google.com!k20ni44838qgd.0!nntp.google.com!z60no3236474qgd.1!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Fri, 22 May 2015 09:29:11 -0700 (PDT) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=78.27.123.114; posting-account=QrZwxQoAAAByl3YAWTpexAk3yBYyZMHn NNTP-Posting-Host: 78.27.123.114 References: <127b004d-2163-477b-9209-49d30d2da5e1@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: Subject: Re: Build language with weak typing, then add scaffolding later to strengthen it? From: kalvin.news@gmail.com Injection-Date: Fri, 22 May 2015 16:29:11 +0000 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Received-Bytes: 5113 X-Received-Body-CRC: 399047166 Xref: news.eternal-september.org comp.lang.ada:25953 Date: 2015-05-22T09:29:11-07:00 List-Id: 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 =E9crit : > > 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. > >>=20 > >> 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. > >>=20 > (Making my point clearer after various reactions). >=20 > 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. >=20 > 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. >=20 > 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. >=20 > 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... >=20 > --=20 > 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 i= nt. For example, a low-level harddisk device driver might contain declarations = like this: int cylinder =3D 1; int head =3D 2; int sector =3D 3; So, it is quite easy to do something stupid like this: head =3D sector; The compiler is happy as we assign an int to another int, but clearily we a= re assigning apples to oranges, which is not something that we typically wa= nt 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 hol= ding information about the cylinder, head and sector. This would also docum= ent the code better and convey more of the programmer's intent:=20 typedef int Cylinder; typedef int Head; typedef int Sector; Cylinder cylinder =3D 1; Head head =3D 2; Sector sector =3D 3; In C/C++ it is still allowed to do this stupid assignment without any compi= ler warning or error whatsoever: head =3D sector; In my opinion, this should not be allowed or at least the compiler should g= enerate a big loud warning, as we were stating specifically that the variab= le 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 th= e Cylinder, Head and Sector and they should not be intermixed unless they a= re 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;