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: 103376,b87849933931bc93 X-Google-Attributes: gid103376,public X-Google-Thread: 1111a3,5ee869da42505971 X-Google-Attributes: gid1111a3,public X-Google-Thread: 1108a1,b87849933931bc93 X-Google-Attributes: gid1108a1,public X-Google-Thread: 114809,b87849933931bc93 X-Google-Attributes: gid114809,public From: nurban@csugrad.cs.vt.edu (Nathan M. Urban) Subject: Re: Combining dynamic and static typing Date: 1997/01/28 Message-ID: <5cloqm$9kn@csugrad.cs.vt.edu>#1/1 X-Deja-AN: 212817104 references: <5celpp$n3r@csugrad.cs.vt.edu> <1997Jan28.160420.28915@schbbs.mot.com> organization: Virginia Polytechnic Institute and State University reply-to: nurban@vt.edu newsgroups: comp.lang.eiffel,comp.lang.ada,comp.lang.c++,comp.lang.smalltalk,comp.lang.objective-c,comp.object Date: 1997-01-28T00:00:00+00:00 List-Id: In article <1997Jan28.160420.28915@schbbs.mot.com>, shang@corp.mot.com wrote: > In article <5celpp$n3r@csugrad.cs.vt.edu> nurban@csugrad.cs.vt.edu (Nathan M. > Urban) writes: > > Thus, Objective-C gives you all the safety of C++'s static type > > checking, while retaining all the advantages of a dynamic language. > The advantage of static type checking is type error prevention: > to prevent type errors before it can happen. > Therefore, Objective-C cannot give the benefit of a static typing > system. Objective-C detects the type errors such as "Not a String" > at run-time. It does detection, not prevention! Detection is usually > not a solution to a problem. It is like an irresponsible doctor saying: > "Now I find what is wrong with you, it's your responsibility to figure > how to fix it. Want my suggetion? -- peace die -- crash!" Compile-time detection _is_ prevention. If you get build errors all over the place, you fix them. Now, there are circumstances under which you need to generate method dispatches at runtime -- which C++ cannot do -- that can't be detected at compile-time. Objective-C gives you the power to do that, and if you send a bad message, you can trap the exception and do something with it. You can even check to see if an object responds to a message before you send it, if you don't want to trap it. This is a better solution than not being able to have that power at all. Programs don't have to crash on a runtime exception. If you want total safety without the possibility of generating a runtime exception, then if you don't need dynamic message generation in your program, it is trivial to write code that does not generate method dispatches at runtime, just like C++; if you don't need the extra power of Objective-C, then you don't have to write your code to use it. If you are writing code that needs dynamic message generation, then sending the wrong message is almost never something that should crash the program, anyway.. suppose you have an application that gets passed unknown object, and its job is to print that object. It send that object the "print" message. If that object does not respond to print, it's not crash-and-burn time, it's just something that can't be printed. So you come back and say, "This object can't be printed", and go about your business. I'd like an example of a case in which dynamic message generation would produce a fatal error in a program. -- Nathan Urban | nurban@vt.edu | Undergrad {CS,Physics,Math} | Virginia Tech