digitalmars.D - Proporsal for cast syntax change
- Juanjo =?ISO-8859-15?Q?=C1lvarez?= (6/6) Aug 02 2004 Maybe it's too late for this, but I think:
- Andy Friesen (4/14) Aug 02 2004 Suffice to say that this exact syntax has been proposed by unrelated
- Juanjo =?ISO-8859-15?Q?=C1lvarez?= (10/24) Aug 03 2004 Another reason, we've
- Andy Friesen (8/43) Aug 03 2004 I would argue that it doesn't matter: if you're casting a lot, you may
- Arcane Jill (10/15) Aug 03 2004 cast(Figure) Square; // Double cast achieves nothing.
- Matthew (2/25) Aug 03 2004 Surprisingly, the second one, i.e. the current syntax
- J C Calvarese (12/22) Aug 03 2004 By my count, it's the same number of parentheses (and it adds a comma).
- Matthew (7/26) Aug 03 2004 There's nothing wrong with it, since it's uniquely greppable (and theref...
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?
Aug 02 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
Aug 02 2004
Andy Friesen wrote:Juanjo Álvarez wrote:Another reason, we've Figure Rectangle Square Now compare: cast( Figure, cast( Rectangle, Square) ); with cast(Figure) ( cast(Rectangle) Square ); Which is more readable?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. :)
Aug 03 2004
Juanjo Álvarez wrote:Andy Friesen wrote: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) -- andyJuanjo Álvarez wrote:Another reason, we've Figure Rectangle Square Now compare: cast( Figure, cast( Rectangle, Square) ); with cast(Figure) ( cast(Rectangle) Square ); Which is more readable?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. :)
Aug 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
Aug 03 2004
"Juanjo Álvarez" <juanjuxNO SPAMyahoo.es> wrote in message news:cenej0$sae$1 digitaldaemon.com...Andy Friesen wrote:Surprisingly, the second one, i.e. the current syntaxJuanjo Álvarez wrote:Another reason, we've Figure Rectangle Square Now compare: cast( Figure, cast( Rectangle, Square) ); with cast(Figure) ( cast(Rectangle) Square );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. :)
Aug 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?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/
Aug 03 2004
"J C Calvarese" <jcc7 cox.net> wrote in message news:ceptnf$1vjb$1 digitaldaemon.com...Juanjo Álvarez wrote: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.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.
Aug 03 2004