Thread overview
Proporsal for cast syntax change
Aug 03, 2004
Juanjo Álvarez
Aug 03, 2004
Andy Friesen
Aug 03, 2004
Juanjo Álvarez
Aug 03, 2004
Andy Friesen
Aug 03, 2004
Arcane Jill
Aug 03, 2004
Matthew
Aug 04, 2004
J C Calvarese
Aug 04, 2004
Matthew
August 03, 2004
Maybe it's too late for this, but I think:

cast( int, 34.5 );

looks a lot nicer than:

cast( int) 34.5;

less parenthesis; function call-like syntax... don't know, what do you people think?
August 03, 2004
Juanjo Álvarez wrote:
> Maybe it's too late for this, but I think:
> 
> cast( int, 34.5 );
> 
> looks a lot nicer than:
> 
> cast( int) 34.5;
> 
> less parenthesis; function call-like syntax... don't know, what do you
> people think?

Suffice to say that this exact syntax has been proposed by unrelated individuals at least three times over the past year or so. :)

 -- andy
August 03, 2004
Andy Friesen wrote:

> Juanjo Álvarez wrote:
>> Maybe it's too late for this, but I think:
>> 
>> cast( int, 34.5 );
>> 
>> looks a lot nicer than:
>> 
>> cast( int) 34.5;
>> 
>> less parenthesis; function call-like syntax... don't know, what do you people think?
> 
> Suffice to say that this exact syntax has been proposed by unrelated individuals at least three times over the past year or so. :)

Another reason, we've

Figure
  Rectangle
    Square

Now compare:

cast( Figure, cast( Rectangle, Square) );

with

cast(Figure) ( cast(Rectangle) Square );

Which is more readable?
August 03, 2004
Juanjo Álvarez wrote:
> Andy Friesen wrote:
> 
> 
>>Juanjo Álvarez wrote:
>>
>>>Maybe it's too late for this, but I think:
>>>
>>>cast( int, 34.5 );
>>>
>>>looks a lot nicer than:
>>>
>>>cast( int) 34.5;
>>>
>>>less parenthesis; function call-like syntax... don't know, what do you
>>>people think?
>>
>>Suffice to say that this exact syntax has been proposed by unrelated
>>individuals at least three times over the past year or so. :)
> 
> 
> Another reason, we've
> 
> Figure
>   Rectangle
>     Square
> 
> Now compare:
> 
> cast( Figure, cast( Rectangle, Square) );
> 
> with
> 
> cast(Figure) ( cast(Rectangle) Square );
> 
> Which is more readable?

I would argue that it doesn't matter: if you're casting a lot, you may have other problems.  Bear in mind, though, that I rather like the C++ cast syntax because it's so ugly.  It is, after all, an ugly concept. :)

At any rate, double-casting is only ever needed when you are doing things that you absolutely should not ever do: casting object references to and from non-pointer types. (confusing the GC is a Bad Idea)

 -- andy
August 03, 2004
In article <cenej0$sae$1@digitaldaemon.com>, Juanjo =?ISO-8859-15?Q?=C1lvarez?= says...
>
>Now compare:
>
>cast( Figure, cast( Rectangle, Square) );
>
>with
>
>cast(Figure) ( cast(Rectangle) Square );
>
>Which is more readable?

cast(Figure) Square; // Double cast achieves nothing.

<sarcasm>Hey, let's copy C++:
static_cast!(int)(x)
dynamic_cast!(int)(x)
reinterpret_cast!(int)(x)
const_cast!(int)(x)
</sarcasm>

Arcane Jill


August 03, 2004
"Juanjo Álvarez" <juanjuxNO@SPAMyahoo.es> wrote in message news:cenej0$sae$1@digitaldaemon.com...
> Andy Friesen wrote:
>
> > Juanjo Álvarez wrote:
> >> Maybe it's too late for this, but I think:
> >>
> >> cast( int, 34.5 );
> >>
> >> looks a lot nicer than:
> >>
> >> cast( int) 34.5;
> >>
> >> less parenthesis; function call-like syntax... don't know, what do you people think?
> >
> > Suffice to say that this exact syntax has been proposed by unrelated individuals at least three times over the past year or so. :)
>
> Another reason, we've
>
> Figure
>   Rectangle
>     Square
>
> Now compare:
>
> cast( Figure, cast( Rectangle, Square) );
>
> with
>
> cast(Figure) ( cast(Rectangle) Square );

Surprisingly, the second one, i.e. the current syntax


August 04, 2004
Juanjo Álvarez wrote:
> Maybe it's too late for this, but I think:
> 
> cast( int, 34.5 );
> 
> looks a lot nicer than:
> 
> cast( int) 34.5;
> 
> less parenthesis; function call-like syntax... don't know, what do you
> people think?

By my count, it's the same number of parentheses (and it adds a comma). Explain to me how that's a benefit. ;)

Anyways, I don't see what the problem is with the current much-maligned cast syntax. It's only slightly different than the C-style, so it shouldn't be hard for C/C++ pros to learn. It doesn't require a tremendous amount of typing, and it's readable. And, as others have written, if a person is doing a lot of casting it could be the sign of a poor design.

-- 
Justin (a/k/a jcc7)
http://jcc_7.tripod.com/d/
August 04, 2004
"J C Calvarese" <jcc7@cox.net> wrote in message news:ceptnf$1vjb$1@digitaldaemon.com...
> Juanjo Álvarez wrote:
> > Maybe it's too late for this, but I think:
> >
> > cast( int, 34.5 );
> >
> > looks a lot nicer than:
> >
> > cast( int) 34.5;
> >
> > less parenthesis; function call-like syntax... don't know, what do you people think?
>
> By my count, it's the same number of parentheses (and it adds a comma).
> Explain to me how that's a benefit. ;)
>
> Anyways, I don't see what the problem is with the current much-maligned cast syntax. It's only slightly different than the C-style, so it shouldn't be hard for C/C++ pros to learn. It doesn't require a tremendous amount of typing, and it's readable. And, as others have written, if a person is doing a lot of casting it could be the sign of a poor design.

There's nothing wrong with it, since it's uniquely greppable (and therefore supportive of automation-assisted code review). That was the major flaw with C-style casts.

In terms of what it does, it can be argued that one cast to cast them all is a little careless, wrt C++'s delineation of casting responsibilities, but I can live with it because it's greppable.

And your last line has it correct. I try to keep the casting abstracted into worker functions, and then use the D types in the main functional code. That works pretty well.