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.2 required=5.0 tests=BAYES_00,INVALID_MSGID, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,2e71cf22768a124d X-Google-Attributes: gid103376,public X-Google-Thread: 1014db,9d58048b8113c00f X-Google-Attributes: gid1014db,public From: O'Connor Subject: Re: next "big" language?? (disagree) Date: 1996/06/08 Message-ID: <31B9B514.37A3@apci.net>#1/1 X-Deja-AN: 159145690 references: <4p3nqb$k4a@btmpjg.god.bel.alcatel.be> <4p3nto$k4a@btmpjg.god.bel.alcatel.be> content-type: text/plain; charset=us-ascii organization: Applied Personal Computing, Inc. mime-version: 1.0 reply-to: oconnor@apci.net newsgroups: comp.lang.ada,comp.lang.c x-mailer: Mozilla 3.0b4 (Win16; I) Date: 1996-06-08T00:00:00+00:00 List-Id: Richard Riehle wrote: > > On Thu, 6 Jun 1996, Richard Riehle wrote: > > To Anyone who might have noticed: > > I guess I should desk-check my code more carefully. The example shown > below would generate a compile-time error due to a type mismatch. Better > to have defined the index type as a subtype of Positive, or even Integer > than a a distinct type. This points out one of the benefits of Ada: > when sloppy coders, such as I seem to be, make this kind of error, it > is easily detected and rejected by the compiler. > > Sorry for the coding error. Mea culpa. The offending code follows: > > Richard Riehle But is this truly an 'error' in that your code does not express your requirements? The problem isn't with what your are trying to accomplish. The problem is that you have violated the language's rules for how to express a particular idea. As such, the compiler has merely enforced the language rules. Any decent compiler for any language will enforce the rules for that language. As a personal opinion, I think the Ada typing rules caused you to make the error in the first place that you compliment the compiler for catching. > > > type T1 is range 1..10; > > -- change the preceding to > subtype T1 is Positive range 1..10; > If I was doing this in Smalltalk I could do it a number of ways; depending on why I was trying to constrain it. For example, if I just needed a generic concept of an contrained range Integer, I would probably subclass Integer and added supporting instance variables and methods. The limits on the new class would be either instance variables to allow each object to have individual limits, or class variables to enforce common limits across all objects of the class. The attraction of the class limit approach would be that I could use Class methods to accomplish the various range looping mechanisms. If instead I had some Domain Object (a Bank Account) whose attributes had domain contraints against their values; I would probably write range checking code into the various get and set methods. If I wanted a more dynamic solution, I would probably use some sort of Validator class. One interesting idea is that fact that the contraints agianst the values of an attribute are contingent on the values in other attributes in the object, or other objects. "X must be between 1 and 5 if Y is less then 7, otherwise X must be between 4 and 12." Expressing such rules is not as straightforward using a simple subtyping approach. Another twist is the idea of using a database table to express the Metadata (including constraints) associated with a particular attribute. The database could hold the limits in values; A Validator object could load these limits when the program started. Changing these limits based on new business conditions could be accomplished with a database update and no code changes at all. Anyway, just some meandering food for thought.... James O'Connor oconnor@apci.net -- ## ## ######## "He that loveth not ######## knoweth not God." ## --1 John 4:8 ## ## ## ##