Minor extension to cast syntax
Gregor Richards
Richards at codu.org
Wed Oct 31 13:48:26 PDT 2007
Bruce Adams wrote:
> Gregor Richards Wrote:
>
>> Blech. Makes it look like you're calling a function with arguments being
>> a type and then some expression. The current syntax is more similar to
>> calling a templated cast function:
>>
>> cast(int)(foo)
>> cast!(int)(foo)
>>
>> That is, cast is a function with a template parameter of the type you're
>> casting it to. This isn't how it's implemented at all of course, but the
>> syntax is reminiscent of that, and I think that's the better analogy.
>>
>> - Gregor Richards
>
> Surely a cast is really a kind of function opCast() so using function syntax is appropriate.
My point was not the function syntax, my point was that it was a
function that takes a type as an argument. That makes no sense.
> The old syntax sticks out as unusual.
Good. Casting is an unusual operation.
> There is that idea in language design that if it can be done as a function it should be unless there is a good reason not to.
In highly dynamic languages where performance isn't a primary objective,
yes. Dynamic arrays, anyone?
> So, having inherited the C like syntax was their ever a good reason for it?
Yes. casting is a procedure which is not similar to anything else in C,
so it has its own syntax.
> does that reason still apply?
Yes, casting is a procedure which is not similar to anything else in D,
so it has its own syntax.
> If you were starting over again (as was supposed to be the case with D) would you still do it this way?
I write dynamic languages :)
>
> Regards,
>
> Bruce.
>
- Gregor Richards
More information about the Digitalmars-d
mailing list