From: Thorsten Ottosen (nesotto_at_[hidden])
Date: 2004-10-08 15:49:20


"Pavol Droba" <droba_at_[hidden]> wrote in message
news:20041008202443.GA22250_at_lenin.felcer.sk...

| > that's not what null objects are for.
|
| So what is the difference between your null-object and 0 pointer?
| I see none, except in your case I will have to define special class/state
| for every type I would like to use the smart_container with.

the point is basically to avoid all if( !null ) logic.

| >
| > > Otherwise, you will have pay the comparison cost every time you perform
an
| > > operation
| > > on the null object, and that might be on far more places.
| > >
| > not understood.
|
| Try to ask Jeff Garland, how many complications it brought when a date class
in date_time
| library was enriched with the special values. Every operation must be aware
of it.
|

yes, the 0 pointer is a special value and we want to avoid the complications
it brings.

| > I need some real code to work with to be able to see this. Then I can
rewrite
| > it to compare.
| >
|
| // Some classes to work with
| class Base
| {
| virtual int Op1() =0;
| ...
| virutal int Op100() =0;
| };
|
|
| class A : public Base
| {
| virtual int Op1() { // do something reasonable and return a valid value
// }
| ..
| virtual int Op100() { // do something reasonable and return a valid value
// }
| };
|
|
| class Null : public Base
| {
| virtual int Op1() { return special_value1; }
| ..
| virtual int Op100() { return special_value100; }
| };

I would return 0 here, in all cases.

| // Now some operations, that use the object of Base.
| // Assume we have 0 pointers
|
| int foo1(Base* pObj)
| {
| // Simple case -> check if oObj is not null
| if(pObj==0)
| return special_value;
| else
| return pObj->Op1() + pObj()->Op2() + ...... + pObj()->Op100();
| }

int foo1( Base& pObj )
{
    return pObj->op1() + ... + pObj->op100();
}

| This example might look realy stupid, but it illustrates well the problem
I'm refering to.
| You cannot assume, that null object will work in the same way as an ordinary
one. Otherwise
| you only pospone the checking one level further -> to its operations and the
objects, that
| uses it.

Yeah, that is really the issue here: are we just forcing users to defer the
comparinson for "nullness"
yet another level. Am eager to be proven wrong, but It's going to take more
convincing examples.

I would like to see real examples and then see if I can recode them so we can
compare. But it has
to be real examples (you must have plenty from your work? Just take one where
you use shared_ptr).
But seriously, I don't recall the need for 0's for a long time.

A long with that code I need to see why there is a need to put a 0 in the
container in the first place and it
would also be nice to know the density of them.

br

Thorsten