[comp.lang.c++] Typed variables

anders@cui.unige.ch (BJORNERSTEDT Anders) (12/07/89)

In article <1989Dec5.055058.26635@odi.com> dlw@odi.com writes:
>In article <22137@brunix.UUCP> sdm@cs.brown.edu (Scott Meyers) writes:
>
>>   I'm having trouble figuring out how to solve the following problem.  Often
>>   I find myself with a collection of objects of a given type, where some of
>>   them define a particular function and some of them don't, and I want to
>>   invoke the function on only those objects for which it is defined.  
>
>I believe that your analysis is completely correct: the options are as
>you have stated them.  In my own personal understanding of the
>philosophy behind C++, approach 1 is the recommended course.  (That
>is, it's just my humble opinion. Approach 2 strikes me as clumsier
>than approach 1, and approach 3 throws the baby out with the bathwater.)

For C++ yes I agree.

>
>In OO languages in which variables are not typed, such as Smalltalk-80
>and Lisp-with-Flavors/CLOS, you wouldn't have any problem.  In fact,

Yes, except not being type safe could be seen as a problem.

<stuff deleted>
>You could look at it as a tradeoff.  The C++ style of typed variables
>provides you with extra checking; but you have to do extra work while
>programming in exchange.  There are similar tradeoffs to be found in
>comparisons of the typed-variable and untyped-variable languages.
<stuff deleted>

Dont forget though that "lexically apparent" typing (or static typing)
is not quite the same thing as type safe. Going back to old Simula,
where all variables are typed, but where both static and dynamic type
checking is used, you have an INSPECT WHEN clause which allows you to build
a case statement where you switch on the type of the instance.
Thus the (sort of academic) point I am making is that you can have type
safety and the "if-handled" sort of thing that Scott Meyers wanted in the
same language, although not in current c++.

Anders

---------------------------------------------------------------------
Anders Bjornerstedt			E-mail: anders@cuisun.unige.ch
Centre Universitaire d'Informatique             
12 rue du Lac, CH-1207 Geneva
---------------------------------------------------------------------
Tel:    41 (22) 787.65.80-87             Fax:    41 (22) 735.39.05
Home:   41 (22) 735.00.03                Telex:  423 801 UNI CH
---------------------------------------------------------------------