Thread overview
stupid cast sintax... why?
Sep 15, 2004
Ant
Sep 15, 2004
kinghajj
Re: stupid cast syntax... why?
Sep 15, 2004
Andy Friesen
Sep 15, 2004
Ant
Sep 15, 2004
Vathix
Sep 15, 2004
Ant
Sep 15, 2004
Stewart Gordon
Re: stupid cast syntax... why?
Sep 15, 2004
Arcane Jill
September 15, 2004
look at this:

return target.opCmp((cast(ProjectTarget)object).getTarget());

makes no sense...

for the new guys - here is how it should be:

return target.opCmp(object.castTo(ProjectTarget).getTarget());

this was discussed before and Walter is not interested at all. save your typing for better battles...

Ant

September 15, 2004
In article <pan.2004.09.15.02.26.07.97659@yahoo.ca>, Ant says...
>
>look at this:
>
>return target.opCmp((cast(ProjectTarget)object).getTarget());
>
>makes no sense...
>
>for the new guys - here is how it should be:
>
>return target.opCmp(object.castTo(ProjectTarget).getTarget());
>
>this was discussed before and Walter is not interested at all. save your typing for better battles...
>
>Ant
>
Your way is worse. It makes D look more like a scripting language than a programming language, IMO... I guess as long as I had a choice on which method to use, I'd be OK with it.


September 15, 2004
Ant wrote:
> look at this:
> 
> return target.opCmp((cast(ProjectTarget)object).getTarget());
> 
> makes no sense...
> 
> for the new guys - here is how it should be:
> 
> return target.opCmp(object.castTo(ProjectTarget).getTarget());

Why?  The present syntax cannot be confused for anything but a cast, by either a human or a computer.

> this was discussed before and Walter is not interested at all.
> save your typing for better battles...

So why bring it up?

 -- andy
September 15, 2004
On Tue, 14 Sep 2004 21:24:54 -0700, Andy Friesen wrote:

> Ant wrote:
>> look at this:
>> 
>> return target.opCmp((cast(ProjectTarget)object).getTarget());
>> 
>> makes no sense...
>> 
>> for the new guys - here is how it should be:
>> 
>> return target.opCmp(object.castTo(ProjectTarget).getTarget());
> 
> Why?  The present syntax cannot be confused for anything but a cast, by either a human or a computer.
> 
>> this was discussed before and Walter is not interested at all. save your typing for better battles...
> 
> So why bring it up?
> 
>   -- andy

because I just had to type that stupid line.

Ant

September 15, 2004
Just messing around...

template castTo()
{
   template castTo(To)
   {
      To castTo() { return cast(To)this; }
   }
}
class Foo
{
   mixin castTo;
   void printName() { printf("Foo\n"); }
}
class Bar: Foo
{
   void printName() { printf("Bar\n"); }
}
int main()
{
   Foo f = new Bar;
   Bar b = f.castTo!(Bar);
   b.printName();
   return 0;
}


September 15, 2004
On Wed, 15 Sep 2004 01:04:57 -0400, Vathix wrote:

> Just messing around...
> 
> template castTo()
...


nice! now we just need to be able to provide our Object class instead of using the predefined.

Ant


September 15, 2004
In article <pan.2004.09.15.02.26.07.97659@yahoo.ca>, Ant says...
>
>look at this:
>
>return target.opCmp((cast(ProjectTarget)object).getTarget());
>
>makes no sense...

..and it will segfault/access-violate if object is not some subclass of ProjectTarget. May I suggest the code should instead be:

#    ProjectTarget t = cast(ProjectTarget) object;
#    return (t === null) ? 0 : opCmp(t.getTarget);

or something similar.
Arcane Jill


September 15, 2004
Ant wrote:

> On Wed, 15 Sep 2004 01:04:57 -0400, Vathix wrote:
> 
>> Just messing around...
>>
>> template castTo()
> 
> ...
> 
> nice! now we just need to be able to provide our Object class
> instead of using the predefined.

If it's going to be useful for generic programming, it'll need to be a defined method of everything, not just Object.

Stewart.

-- 
My e-mail is valid but not my primary mailbox.  Please keep replies on the 'group where everyone may benefit.