www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - stupid cast sintax... why?

reply Ant <duitoolkit yahoo.ca> writes:
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
Sep 14 2004
next sibling parent kinghajj <kinghajj_member pathlink.com> writes:
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

programming language, IMO... I guess as long as I had a choice on which method to use, I'd be OK with it.
Sep 14 2004
prev sibling next sibling parent reply Andy Friesen <andy ikagames.com> writes:
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
Sep 14 2004
parent Ant <duitoolkit yahoo.ca> writes:
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
Sep 14 2004
prev sibling next sibling parent reply "Vathix" <vathixSpamFix dprogramming.com> writes:
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;
}
Sep 14 2004
parent reply Ant <duitoolkit yahoo.ca> writes:
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
Sep 14 2004
parent Stewart Gordon <smjg_1998 yahoo.com> writes:
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.
Sep 15 2004
prev sibling parent Arcane Jill <Arcane_member pathlink.com> writes:
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
Sep 15 2004