[Mono-list] Object additional implicit operator.

Adrien Dessemond adrien.dessemond at softhome.net
Fri Aug 15 14:28:13 EDT 2008


On Fri, August 15, 2008 1:20 pm, d3x0r wrote:

Hi !

> Sorry, I'll drop this point.
>
> It would have been really really simple when the language was conceived to
> consider that a simple test for object existance should not require the
> specification of a null constant; nor should it require the extra overhead
> of a comparison operator.  A really simple check for existance.

Very good point indeed !

The goal of the implicit operator is to do help with type casting, not
object existence checking. 'Object' is a very general concept as it
represents anything. You cannot assume that an existence check is THE
thing to do when you type-cast anything to a boolean and this is exactly
why methods at the 'Object' level are limited to their strict bare
minimum. Too general to decide what an 'Object' can do or cannot do.

Okay, let's add something like an "Exists" property that do what your code
do :

if (! myobjet.Exists) ....

VS

if (myobjet == null)


Imagine the overhead : in the first case, 2 tests and a negation plus the
overhead of the call. In the second one, you only have one comparison. May
I miss a point there, but the second way is more compact and efficient.
And it brings another point : what do with abstract classes as 'Exists' in
their case is totally meaningless ? No sense and a funny design error !

You can resolve your issue with a factory pattern, this is a more elegant
way of doing what you want to do :-) And the best, is is portable.

http://msdn.microsoft.com/en-us/library/ms954600.aspx

Hope it will help you ! Do not hesitate to ask is you need more help.


Cheers,

Adrien





More information about the Mono-list mailing list