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=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID 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: 1108a1,b87849933931bc93 X-Google-Attributes: gid1108a1,public X-Google-Thread: 103376,b87849933931bc93 X-Google-Attributes: gid103376,public X-Google-Thread: 114809,b87849933931bc93 X-Google-Attributes: gid114809,public From: mheaney@ni.net (Matthew Heaney) Subject: Re: What is wrong with OO ? Date: 1997/01/19 Message-ID: #1/1 X-Deja-AN: 210803435 references: <32D11FD3.41C6@wi.leidenuniv.nl> <01bc002f$b4dd5bc0$6ba3aec7@mycomputer> content-type: text/plain; charset=ISO-8859-1 organization: Estormza Software mime-version: 1.0 newsgroups: comp.lang.c++,comp.lang.smalltalk,comp.lang.eiffel,comp.lang.ada,comp.object,comp.software-eng Date: 1997-01-19T00:00:00+00:00 List-Id: In article , bs@research.att.com (Bjarne Stroustrup) wrote: > > Why let me use > > uninitialized pointers? Do you have any idea how many programs I have > > debugged for hours because someone failed to write something as basic as: > > > > char *p = NULL; > >If I had designed C++ today, every variable that did not have a default >constructor would have to be initialized. Perhaps it has already been stated elsewhere in this thread, but in Ada, access objects are by default initialized to null. An attempt to dereference a null access value raises Constraint_Error. I see C++, Ada, and Eiffel being on a scale of safety with respect to pointers (and other things, too). Eiffel takes the attitude that pointers are unsafe (they can be), so removes them from the language. This is the approach taken by Java, too. C++ is pragmatic, and given its C and systems-programming roots, has pointers, and you can basically do anything you want. In fact, a pointers are often used to do a typeless kind of programming; this is the norm, for example, in making UNIX system calls. But there is little safety in that approach, and your example proves the point that perhaps some built-in support for pointer-safe programming is called for. Ada is in the middle: it's pragmatic *and* safe. You are free to use pointers, but pointer type "casting" is not allowed. Pointers to statically declared objects are safe too, because you are only allowed to point to an object that has a longer life than you. "Reference" variables are made safe by parameterizing the object with a reference to a longer-lived object. Of course, if you really do want to leave the type system in Ada, you can do so by explicitly marking the conversion or dereference as "unchecked." So you can have your cake and eat it too. I have said it before: I like Eiffel, and don't disagree with its philosophy, but I think there's room for pragmatism. I think Bjarne would agree that it's important to give programmers all the tools they need to do their job, and that includes pointers. Ada's philosophy is give them pointers, but make pointer manipulation safe. If you are frustrated by repairing code that is broken because of non-initialized pointers, then perhaps you should give Ada a try. Programming is a lot more productive then debugging, and a lot less frustrating. -matt -------------------------------------------------------------------- Matthew Heaney Software Development Consultant (818) 985-1271