Newsgroups: comp.software-eng,comp.object,comp.lang.eiffel,comp.lang.smalltalk,comp.lang.modula3,comp.lang.objective-c
Path: cantaloupe.srv.cs.cmu.edu!das-news.harvard.edu!news2.near.net!MathWorks.Com!solaris.cc.vt.edu!uunet!rcm!rmartin
From: rmartin@rcmcon.com (Robert Martin)
Subject: Re: Static vs Dynamic Typing: Effects on Productivity?
References: <DERWAY.94Aug23180251@alumni.ndc.com> <33u5un$ppr@vienna.eiffel.com> <340dcc$qn8@larry.rice.edu>
Organization: R. C. M. Consulting Inc. 708-918-1004
Date: Thu, 1 Sep 1994 05:12:06 GMT
Message-ID: <1994Sep1.051206.18162@rcmcon.com>
Lines: 30
Xref: glinda.oz.cs.cmu.edu comp.software-eng:25289 comp.object:19963 comp.lang.eiffel:6260 comp.lang.smalltalk:16114 comp.lang.modula3:2936 comp.lang.objective-c:3009

amitp@owlnet.rice.edu (Amit Jayant Patel) writes:

>I have often heard that "most" C++ programs use casts.  However, I
>haven't found any place where I needed them, other than const-casts,
>which are no longer needed with the 'mutable' keyword.

>Can someone give examples of where casts are necessary in C++?  I have
>not worked on medium or large programs yet, so I may just be lacking
>experience.

Casts in C++ are not almost always unecessary and unwanted.  There are
times when dynamic_cast is useful, but this is more a test and less a
cast.  

If we ignore novices, Casts are most often used in C++ by people who
are used to programming in dynamically typed languages (like
Smalltalk).  They have difficulty with the type system and are not
used to the restrictions it imposes.  Thus they use casts to do the
same things that they would have done in their dynamically typed
language.  What they need to do instead, is change their style. 

The style needed for programming in a statically typed language is
quite different from that needed for a dynamically typed language.
Once this transition is made, the casts in C++ disappear.

-- 
Robert Martin       | Design Consulting   | Training courses offered:
Object Mentor Assoc.| rmartin@rcmcon.com  |   Object Oriented Analysis
2080 Cranbrook Rd.  | Tel: (708) 918-1004 |   Object Oriented Design
Green Oaks IL 60048 | Fax: (708) 918-1023 |   C++
