Re: A C++ Whishlist
From: Ram Firestone (bichir_at_covad.net)
Date: 03/19/04
- Next message: E. Robert Tisdale: "Off Topic: Proposal: a language showdown - not necessarily here."
- Previous message: Victor Bazarov: "Re: Namespaces, 'using' directives and 'using' declarations?"
- In reply to: Old Wolf: "Re: A C++ Whishlist"
- Next in thread: Old Wolf: "Re: A C++ Whishlist"
- Reply: Old Wolf: "Re: A C++ Whishlist"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 18 Mar 2004 20:38:29 -0800
oldwolf@inspire.net.nz (Old Wolf) wrote in message news:<843a4f78.0403181343.6d3c6267@posting.google.com>...
> > > > > #include <iostream>
> > > > > class foo
> > > > > {
> > > > > int a;
> > > > > public:
> > > > > void dump() { std::cout << a << std::endl; }
> > > > > };
> > > > >
> > > > > because someone might write:
> > > > >
> > > > > int main()
> > > > > {
> > > > > foo *f = NULL;
> > > > > f->dump();
> > > > > }
>
> [snip: a screenful of argument about whether or not to throw exceptions]
>
> My class foo cannot throw an exception, if UB has not been introduced
> by someone else already. So the current Standard is better in this
> respect too.
>
Except your class can and will throw an exception on almost every
computer. That's what I meant by a fantasy world. On your fantasy
computer your member function can't throw an exception.
> > > My function "foo::dump()" can never introduce undefined behaviour,
> > > according to the current Standard.
> > >
> > > Encapsulation is one of the cornerstones of C++ : I can take
> > > this class foo and use it anywhere, anyhow I like, in any project
> > > at any time in the future, and be 100% certain that it will never
> > > introduce undefined behaviour, regardless of how it is called.
> > > The same cannot be said of your func.
> >
> > In a fantasy world this is true
>
> In the real world this is true. There are millions of C++ components,
> classes, etc. which have been debugged and tested and then re-used
> in a variety of applications. If we give my class foo a suitable
> constructor, then it can join that list.
>
And they will all crash in the exact same place if you call their
members with a NULL pointer on almost all computers out there. On the
any others they will crash before the member call. So what's your
point? The result is the same.
> , in reality almost all compilers will
> > pass your NULL though to the this pointer so you are in the exacty
> > same boat I am.
>
> Not at all. I couldn't care less if someone introduces UB and then
> attempts to use my class. The bottom line is that my class cannot
> introduce UB and yours can. Both of our examples are equally as
> efficient. Mine is already robust; if you want to make yours robust
> then you have to add in an extra check against NULL.
You know I can't argue with you because I don't think have an
understanding of what happens in a member function call. Again your
class is robust on very few computers if any. In addition the outcome
is the same if you call a member with NULL on all computers, the
program crashes. Bottom line, if you want the program to be robust you
have to put in a check and handle it somewhere. You never get it for
free. Doesn't matter if the standard is changed or not. It still
crashes. If want it to crash outside of you class you have to put in a
check because the calling through NULL is undefined which means that
if you do it you can't guarantee that the this pointer will not be
NULL and in almost all cases it will actually be NULL. You can whine
to the gods about standards and well-formed programs forever and in
the end the this pointer will still be NULL and your program will
still crash. Your robustness advantage is strictly in your head.
Ram
- Next message: E. Robert Tisdale: "Off Topic: Proposal: a language showdown - not necessarily here."
- Previous message: Victor Bazarov: "Re: Namespaces, 'using' directives and 'using' declarations?"
- In reply to: Old Wolf: "Re: A C++ Whishlist"
- Next in thread: Old Wolf: "Re: A C++ Whishlist"
- Reply: Old Wolf: "Re: A C++ Whishlist"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|