Thread overview | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
September 15, 2004 stupid cast sintax... why? | ||||
---|---|---|---|---|
| ||||
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 Re: stupid cast sintax... why? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ant | 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 Re: stupid cast syntax... why? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ant | 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 Re: stupid cast syntax... why? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andy Friesen | 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 Re: stupid cast sintax... why? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ant | 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 Re: stupid cast sintax... why? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Vathix | 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 Re: stupid cast syntax... why? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ant | 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 Re: stupid cast sintax... why? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ant | 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. |
Copyright © 1999-2021 by the D Language Foundation