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=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f891f,9d58048b8113c00f X-Google-Attributes: gidf891f,public X-Google-Thread: 10cc59,9d58048b8113c00f X-Google-Attributes: gid10cc59,public X-Google-Thread: 1014db,9d58048b8113c00f X-Google-Attributes: gid1014db,public X-Google-Thread: 103376,2e71cf22768a124d X-Google-Attributes: gid103376,public From: jsa@organon.com (Jon S Anthony) Subject: Re: next "big" language?? (disagree) Date: 1996/06/11 Message-ID: #1/1 X-Deja-AN: 159694759 sender: news@organon.com (news) references: <4p0fdd$4ml@news.atlantic.net> organization: Organon Motives, Inc. newsgroups: comp.lang.pascal,comp.lang.c,comp.lang.misc,comp.lang.ada Date: 1996-06-11T00:00:00+00:00 List-Id: In article <4pj7v8$g3c@goanna.cs.rmit.EDU.AU> rav@goanna.cs.rmit.EDU.AU (++ robin) writes: > fjh@mundook.cs.mu.OZ.AU (Fergus Henderson) writes: > > >johmann@moal.com (Kurt Johmann) writes: > > >>Range checking, IMO, is something that should be > >>checked by the programmer's code as needed. For example: > >> > >> assert(x > 0 && x < 10); // int x must be between 1 and 9 inclusive > >> > >>One disadvantage of doing it the Ada way (in which the allowed range is > >>declared as part of the type) is that it is inflexible and global, and > >>the range information is separated from where the variable's value is > >>actually used in the program. > > >I disagree that the Ada way is inflexible. Usually associating a range > >with a type is what you want. > > ---Is it? Typically, yes it is. > Rarely do programs stay the same. Users change > their minds, during program design and after it is complete. What does this have to do with the point??? The kind of situation being described is one most likely dealing with the internal structure of the _implementation_, not the user level requirements! Criminey! > ---Why, someone inevitably decides that the range is going > to be something different! I would hope that your "designs" of the internals of an application are not that sloppy and slipshod. Then again, looking at typical examples of programs certainly doesn't help my faith here... > Users are apt to change their minds. > Then someone has to go in and modify the program. Or, someone > overlooked a limit, and put in a limit one smaller than that > actually required. Again, someone has to go in and find where > that limit is, and change it. Again, get a clue. No one is talking about hard coding restrictions at the user level - unless, of course, those restrictions make sense from the standpoint of the user level model. Trivial example: the user level model imposes the requirement that a current ranges between 3 and 15 units (amperes, milliamps, whatever). That's the designed in range. Anything outside this range is an indication that a fault has/is occuring. Only the feckless would think it is somehow a great idea to just let any value outside this range occur in such a context. Furthermore, you can let this range be specifiable by the user for any given "run" (maybe it's a simulation): subtype Current_Range is range Get_Current_Min .. Get_Current_Max; ... Where the Get_Current* obtain values at runtime. Quick hack: with Ada.Command_Line; use Ada.Command_Line; with Text_Io; use Text_Io; procedure Junk is subtype Current_Range is Integer range Integer'Value(Argument(1))..Integer'Value(Argument(2)); begin Put_Line( "Current_Range = " & Integer'Image(Current_Range'First) & " .." & Integer'Image(Current_Range'Last) ); end; $ gnatmake junk.adb $ junk 1 4 Current_Range = 1 .. 4 $ junk 4 8 Current_Range = 4 .. 8 $ Looks to me like both the flexibility _and_ the safety. Really, if you are going to comment, at least have some idea of what you're talking about. > > But Ada also provides ways of suppressing > >range checks or of adding arbitrary assertions in a manner equivalent > >to C's assert. > > ---and I suppose it never has happened that someone forgot to > suppress a range check . . . Irrelevant. If you don't want a range then DON'T specify one. You can let it be whatever you want. The difference is that in Ada you _can_ specify a range as a definition if you know that this is correct and the language will ensure that this is enforced. /Jon -- Jon Anthony Organon Motives, Inc. 1 Williston Road, Suite 4 Belmont, MA 02178 617.484.3383 jsa@organon.com