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: fac41,b87849933931bc93 X-Google-Attributes: gidfac41,public X-Google-Thread: 109fba,b87849933931bc93 X-Google-Attributes: gid109fba,public X-Google-Thread: f43e6,b87849933931bc93 X-Google-Attributes: gidf43e6,public X-Google-Thread: 103376,b87849933931bc93 X-Google-Attributes: gid103376,public X-Google-Thread: 1108a1,b87849933931bc93 X-Google-Attributes: gid1108a1,public X-Google-Thread: 114809,b87849933931bc93 X-Google-Attributes: gid114809,public From: traymond@craftedsmalltalk.com Subject: Re: OO, C++, and something much better! Date: 1997/01/24 Message-ID: #1/1 X-Deja-AN: 211960353 sender: traymond@craftedsmalltalk.com references: <32DF458F.4D5C@concentric.net> <32DF94DC.6FF8@watson.ibm.com> <32DFD972.37E4@concentric.net> <32E4FC5B.242C@watson.ibm.com> <32E6862D.608B@parcplace.com> <32E788D4.4B91@watson.ibm.com> organization: Crafted Smalltalk reply-to: traymond@craftedsmalltalk.com (Terry Raymond) newsgroups: comp.lang.c++,comp.lang.smalltalk,comp.lang.eiffel,comp.lang.ada,comp.object,comp.software-eng Date: 1997-01-24T00:00:00+00:00 List-Id: In <32E788D4.4B91@watson.ibm.com>, "Norman H. Cohen" writes: [stuff deleted] :For example, suppose a program has an array of "producer companies" that :manufacture a particular product and an array of "consumer companies" :that buy that product. Suppose the program manipulates both integers :meant to index into the first array and integers meant to index into the :second array. Mistakenly using a variable holding an integer of the :first kind to index into the second array could produce subtle errors :that might be hard to track down, or might just silently produce :incorrect answers. In a strongly typed language such as Ada, one could :write : : type Producer_Number is range 1 .. Max_Producer_Count; : type Consumer_Number is range 1 .. Max_Consumer_Count; : Producers : array (Producer_Number) of Company; : Consumers : array (Consumer_Number) of Company; : :Producer_Number and Consumer_Number are distinct integer types whose :uses cannot be intermixed without an explicit type conversion. (This is :a degree of type protection unavailable in C or C++). Certain variables :can be declared to be of type Producer and others of type Consumer. An :attempt to use a variable of type Producer_Number to index into the :array Consumers will produce a compile-time type error. : :As you said, "Smalltalk does not lend itself to 'type' errors of that :nature." Smalltalk programmers are no less likely than other :programmers to use an integer variable to index into the wrong array, :but since Smalltalk does not have the means to express such distinctions :as type distinctions, I would imagine that most Smalltalk programmers :would think of this as a "general logic error" rather than as the kind :of problem that would be caught by compile-time type checks. (When you :don't have a hammer, none of your problems look like nails.) Sure, smalltalk programmers can index into the wrong array. However, your example appears to be formulated for a procedural style of programming. When smalltalk programmers want to separate consumers and producers they usually use different objects which reduces the tendency to produce the type of errors you refer to. Part of the power of smalltalk is the use of interface polymorphism. Classes do not have to inherit from the same root to be able to use the same message interface. When designing the software for your problem one can compose methods that use polymorphism so that a single method can "operate" on producers and consumers without having to know what it is operating on. As a matter of fact a programmer reading the method may not even be able to tell if it processes consumers or producers because both will work. Smalltalk works quite differently than traditional languages. To appreciate its power you really have to use it, studying it is not enough. Also, you will quite frequently hear people say that it takes them anywhere from 6 months to a year of using smalltalk before their mind set has changed enough so they can really do smalltalk right. The problem is not learning how the library works, though it is a big learning curve, it is changing ones perspective that takes a while. =========================================================== Terry Raymond Smalltalk Professional Debug Package Crafted Smalltalk *Breakpoints* and *Watchpoints* for 19 Tilley Ave. VW and ENVY/Developer Newport, RI 02840 (401) 846-6573 traymond@craftedsmalltalk.com http://www.craftedsmalltalk.com ===========================================================