Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uwm.edu!uwvax!heurikon!ex.heurikon.com!daves From: daves@ex.heurikon.com (Dave Scidmore) Newsgroups: comp.lang.c++ Subject: Re: typesafe downward casting Message-ID: <327@heurikon.heurikon.com> Date: 7 Apr 91 07:26:15 GMT References: <1991Mar30.161252.26129@kodak.kodak.com> <18.UUL1.3#8618@softrue.UUCP> <1991Apr2.161809.16952@kodak.kodak.com> <27FA1EC4.511C@tct.com> Sender: news@heurikon.heurikon.com Reply-To: daves@ex.heurikon.com (Dave Scidmore) Organization: Heurikon Corporation, Madison, WI Lines: 30 cok@islsun.Kodak.COM (David Cok): >I would maintain ... that a good program generally has few casts and a >good programming language allows most programs to be written without casts. Since C, and for the most part C++ as well, are not strongly typed languages and rely on casts to allow the programmer to make explicit changes in type, I would disagree with the above statement. Automatic or built in changes of type are essentially hidden rules which rely on the programmers intimate knowledge of the type structure and possibly even an intimate knowledge of the program to understand what is really happening. As a rule, I tend to like people who write programs I might be required to maintain to make as explicit as possible any subtle changes of type which I might not immediately grasp on first examination of the code. Casts are a means of making clear to other programmers what the original programmer intended. In the absence of casts when hunting down a bug I must constantly ask myself if the original programmer intended the "hidden" type conversion to occur, or whether the programmer was unaware that the type conversion could be taking place. When a cast is provided I have a much higher degree of confidence that what I see happening in the code was what was actually intended. In other words the authors of C provided casts as an alternative to the straight jacket form of type checking that Pascal has. Attempts to provide "hidden" type conversions can easily be used to erode that form of type checking the language provides. Erosion of that type checking provides more pitfalls into which programmers can fall. -- Dave Scidmore, Heurikon Corp. dave.scidmore@heurikon.com