digitalmars.D - Deprecating C style casts
- Walter (11/11) May 05 2004 Currently, D supports C style casts:
- Roel Mathys (5/23) May 05 2004 just do it,
- =?ISO-8859-1?Q?Julio_C=E9sar_Carrascal_Urquijo?= (11/13) May 05 2004 +1
- C (6/19) May 05 2004 Yea rip em out there. I vote yes, take away C style casts.
- Jeroen van Bemmel (5/19) May 05 2004 please do
- imr1984 (3/14) May 05 2004 i dont see what's wrong with C style casts. Exactly how would this propo...
- Andy Friesen (6/8) May 05 2004 I don't think it will.
- Chr. Grade (6/14) May 05 2004 The closer D will remain related to C and Cpp, the more likely people
- Ivan Senji (4/18) May 05 2004 You will easilly get used to D casts because they better show the intent...
- Andy Friesen (5/12) May 05 2004 It seems a pretty tiny syntactic spec, don't you think? The meaning of
- Chr. Grade (8/24) May 05 2004 Either D feels like C/Cpp or it doesn't. Such thing obscures the
- Chris Lawson (9/37) May 05 2004 Keep in mind that the compiler version hasn't crested 1.0 yet. I doubt
- Chr. Grade (2/9) May 05 2004
- Chris Lawson (5/17) May 05 2004 My point is that anyone who would refuse to change their casting syntax
- Chr. Grade (3/8) May 05 2004 I'm not looking for a new language, but an enhancement of C/Cpp.
- Chris Lawson (5/16) May 05 2004 And you want enhancements with zero change in syntax? I don't think
- Matthew (6/13) May 05 2004 Nor is it borne out in experience. I have turned three people onto D who...
- Unknown W. Brackets (28/39) May 05 2004 While personally I am happy with the old syntax.... it did always say to...
- Chr. Grade (12/39) May 05 2004 n/c
- Matthew (8/32) May 05 2004 Good point. As I've said many times in the past, I'd prefer
- Chr. Grade (4/13) May 05 2004 Why the paranthesis? Why wouldn't a syntax like this be applicable?
- J C Calvarese (12/32) May 05 2004 Nostalgia maybe?
- Unknown W. Brackets (24/47) May 05 2004 So does if(true). Scary. But you can always use:
- Lars Ivar Igesund (3/5) May 05 2004 I certainly hope it don't.
- Andy Friesen (6/16) May 05 2004 That's the downside of using a beta compiler for a beta language. The
- Walter (10/18) May 05 2004 I hear you, which is why I put this question here. Also, there are maybe...
- Ilya Minkov (15/22) May 16 2004 C-style cast is informally deprecated even in C++, where you should use
- James McComb (3/5) May 05 2004 +1
- Ivan Senji (3/5) May 05 2004 +1
- Mark T (2/4) May 05 2004 let it go, I had to get used to the new C++ casts, so D casts should be...
- Matthew (3/14) May 05 2004 Do it! No question.
- Walter (9/13) May 05 2004 I should also confess that I'm looking into implementing things like:
- Andy Friesen (5/14) May 05 2004 My head is spinning:
- Walter (6/19) May 05 2004 inscrutable
- =?ISO-8859-1?Q?Julio_C=E9sar_Carrascal_Urquijo?= (12/21) May 06 2004 So does that means we could store a type in a variable! That's the
- C. Sauls (6/15) May 06 2004 Hey... I remember talking about something along these lines some time
- Hauke Duden (11/19) May 09 2004 I like this! But why not use the same method to avoid the ambiguity as
- J C Calvarese (5/21) May 05 2004 I'm definitely in favor of this. Let's get rid of those C-style casts.
- Patrick Down (2/13) May 05 2004
- Russ Lewis (5/21) May 05 2004 Good idea except for the deprecating part. C-style casts have been
- David L. "SpottedTiger" Davis (10/31) May 06 2004 [Warning: 1st post]
- chris (8/12) May 05 2004 i would prefer somthing like...
- Scott Egan (7/18) May 06 2004 I'll never be able to program again. But then the doco already made me
- J Anderson (5/7) May 06 2004 I guess people should start updating there documentation now if they are...
- Mike Wynn (11/22) May 06 2004 do it ... and finally resolve that persistant BUG
- Brad Anderson (10/10) May 17 2004 In DMD 0.89, the following:
- Walter (4/12) May 24 2004 better
Currently, D supports C style casts: (type)expression as well as D style casts: cast(type)expression The C style casts are tricky to parse right, and I think will cause increasing problems down the road due to the syntactical ambiguities with it. The D style cast has no such problems, and it has the advantage of being greppable (as some programming styles consider an explicit cast to be a bug, and being able to find and check them all to be a Good Thing). What do people think about first deprecating, then removing, the C style cast?
May 05 2004
Walter wrote:Currently, D supports C style casts: (type)expression as well as D style casts: cast(type)expression The C style casts are tricky to parse right, and I think will cause increasing problems down the road due to the syntactical ambiguities with it. The D style cast has no such problems, and it has the advantage of being greppable (as some programming styles consider an explicit cast to be a bug, and being able to find and check them all to be a Good Thing). What do people think about first deprecating, then removing, the C style cast?just do it, D has no intention of compiling C code, and it will certainly mark the spots where something funny is going on roel
May 05 2004
Walter wrote:What do people think about first deprecating, then removing, the C style cast?+1 -- Julio César Carrascal Urquijo http://jcesar.f2o.org/ -----BEGIN GEEK CODE BLOCK----- Version: 3.12 GCS$ d- s+:+ a-- C++> ULS++ P++ L+> !E W+++ N+ o? K? w++> O--- M V? PS+ PE Y+ PGP t+ 5- X+++ R- tv+(++) b++> DI! D++> G e+> h-- r- y+ ------END GEEK CODE BLOCK------
May 05 2004
Yea rip em out there. I vote yes, take away C style casts. C On Wed, 5 May 2004 10:04:08 -0700, Walter <newshound digitalmars.com> wrote:Currently, D supports C style casts: (type)expression as well as D style casts: cast(type)expression The C style casts are tricky to parse right, and I think will cause increasing problems down the road due to the syntactical ambiguities with it. The D style cast has no such problems, and it has the advantage of being greppable (as some programming styles consider an explicit cast to be a bug, and being able to find and check them all to be a Good Thing). What do people think about first deprecating, then removing, the C style cast?-- Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
May 05 2004
please do deprecate in the next release, remove in the one after that. Fix is trivial enough to warrant such a short period "Walter" <newshound digitalmars.com> wrote in message news:c7b6vn$1o0h$1 digitaldaemon.com...Currently, D supports C style casts: (type)expression as well as D style casts: cast(type)expression The C style casts are tricky to parse right, and I think will cause increasing problems down the road due to the syntactical ambiguities with it. The D style cast has no such problems, and it has the advantage of being greppable (as some programming styles consider an explicit cast to be a bug, and being able to find and check them all to be a Good Thing). What do people think about first deprecating, then removing, the C style cast?
May 05 2004
i dont see what's wrong with C style casts. Exactly how would this proposal reduce my D-coding bugs? In article <c7b6vn$1o0h$1 digitaldaemon.com>, Walter says...Currently, D supports C style casts: (type)expression as well as D style casts: cast(type)expression The C style casts are tricky to parse right, and I think will cause increasing problems down the road due to the syntactical ambiguities with it. The D style cast has no such problems, and it has the advantage of being greppable (as some programming styles consider an explicit cast to be a bug, and being able to find and check them all to be a Good Thing). What do people think about first deprecating, then removing, the C style cast?
May 05 2004
imr1984 wrote:i dont see what's wrong with C style casts. Exactly how would this proposal reduce my D-coding bugs?I don't think it will. What it will do is make the compiler simpler, and the language easier to parse. That means that the compiler will be faster, and code analyzing tools will be better. -- andy
May 05 2004
The closer D will remain related to C and Cpp, the more likely people are willing to have a closer look at D and programm with it and switch to it. D has to be intuitive for D-newbies. I merely tried D because it looked and felt so familiar. I'd be more than disencouraged if C/Cpp style casts were missing, because I'm simply used to them; I like them.I don't think it will. What it will do is make the compiler simpler, and the language easier to parse. That means that the compiler will be faster, and code analyzing tools will be better. -- andy
May 05 2004
"Chr. Grade" <tickle everymail.net> wrote in message news:c7bdm6$217m$1 digitaldaemon.com...The closer D will remain related to C and Cpp, the more likely people are willing to have a closer look at D and programm with it and switch to it. D has to be intuitive for D-newbies. I merely tried D because it looked and felt so familiar. I'd be more than disencouraged if C/Cpp style casts were missing, because I'm simply used to them; I like them.You will easilly get used to D casts because they better show the intention of the programmer, they are much easier to parse, and find in the code.I don't think it will. What it will do is make the compiler simpler, and the language easier to parse. That means that the compiler will be faster, and code analyzing tools will be better. -- andy
May 05 2004
Chr. Grade wrote:The closer D will remain related to C and Cpp, the more likely people are willing to have a closer look at D and programm with it and switch to it. D has to be intuitive for D-newbies. I merely tried D because it looked and felt so familiar. I'd be more than disencouraged if C/Cpp style casts were missing, because I'm simply used to them; I like them.It seems a pretty tiny syntactic spec, don't you think? The meaning of a cast is still utterly the same; it's just one tiny keyword which just so happens to vastly simplify things for the implementors. -- andy
May 05 2004
Either D feels like C/Cpp or it doesn't. Such thing obscures the relation to C/Cpp and puts up an obstacle for frist timers. C style casts will be cut out first. And what's next? How many times will I have to partially rewrite my code. Over and over? Every time a new compiler version is released? Programming at Walter's and the D-community's mercy. So, that's the downside of D? And where's the C hardcore faction?Chr. Grade wrote:The closer D will remain related to C and Cpp, the more likely people are willing to have a closer look at D and programm with it and switch to it. D has to be intuitive for D-newbies. I merely tried D because it looked and felt so familiar. I'd be more than disencouraged if C/Cpp style casts were missing, because I'm simply used to them; I like them.It seems a pretty tiny syntactic spec, don't you think? The meaning of a cast is still utterly the same; it's just one tiny keyword which just so happens to vastly simplify things for the implementors. -- andy
May 05 2004
Chr. Grade wrote:Either D feels like C/Cpp or it doesn't. Such thing obscures the relation to C/Cpp and puts up an obstacle for frist timers. C style casts will be cut out first. And what's next? How many times will I have to partially rewrite my code. Over and over? Every time a new compiler version is released? Programming at Walter's and the D-community's mercy. So, that's the downside of D?Keep in mind that the compiler version hasn't crested 1.0 yet. I doubt there will be syntax changes within the 1.x branch. Even within a pre-release compiler the plan is to deprecate then remove C casts, that seems reasonable.And where's the C hardcore faction?Not to put too fine a point on it; they're probably still coding away in C and ignoring most imperative language innovations from the last couple decades. ChrisChr. Grade wrote:The closer D will remain related to C and Cpp, the more likely people are willing to have a closer look at D and programm with it and switch to it. D has to be intuitive for D-newbies. I merely tried D because it looked and felt so familiar. I'd be more than disencouraged if C/Cpp style casts were missing, because I'm simply used to them; I like them.It seems a pretty tiny syntactic spec, don't you think? The meaning of a cast is still utterly the same; it's just one tiny keyword which just so happens to vastly simplify things for the implementors. -- andy
May 05 2004
I love this hazy nuance of absolutism; especially "imperative language innovation".And where's the C hardcore faction? Not to put too fine a point on it; they're probably still coding away in C and ignoring most imperative language innovations from the last couple decades. Chris
May 05 2004
My point is that anyone who would refuse to change their casting syntax probably isn't looking around for new programming languages in the first place. Chris Chr. Grade wrote:I love this hazy nuance of absolutism; especially "imperative language innovation".And where's the C hardcore faction? Not to put too fine a point on it; they're probably still coding away in C and ignoring most imperative language innovations from the last couple decades. Chris
May 05 2004
I'm not looking for a new language, but an enhancement of C/Cpp. People looking for a completely new language won't chose D. Chris Lawson wrote:My point is that anyone who would refuse to change their casting syntax probably isn't looking around for new programming languages in the first place. Chris
May 05 2004
Chr. Grade wrote:I'm not looking for a new language, but an enhancement of C/Cpp.And you want enhancements with zero change in syntax? I don't think that's reasonable.People looking for a completely new language won't chose D.I don't see how that follows. ChrisChris Lawson wrote:My point is that anyone who would refuse to change their casting syntax probably isn't looking around for new programming languages in the first place. Chris
May 05 2004
"Chris Lawson" <cl mangler.tinfoilhat.ca> wrote in message news:c7bmsl$2gi0$1 digitaldaemon.com...Chr. Grade wrote:Nor is it borne out in experience. I have turned three people onto D who've not previously used C or C++ (other than to be scared of them, that is). None of them have yet seen fit to join the rambunctious debate that is the D newsgroup(s), but they are using the language.I'm not looking for a new language, but an enhancement of C/Cpp.And you want enhancements with zero change in syntax? I don't think that's reasonable.People looking for a completely new language won't chose D.I don't see how that follows.
May 05 2004
Chr. Grade wrote:Either D feels like C/Cpp or it doesn't. Such thing obscures the relation to C/Cpp and puts up an obstacle for frist timers. C style casts will be cut out first. And what's next? How many times will I have to partially rewrite my code. Over and over? Every time a new compiler version is released? Programming at Walter's and the D-community's mercy. So, that's the downside of D? And where's the C hardcore faction?While personally I am happy with the old syntax.... it did always say to me "not C-ish". I don't know how you can call it "like C/Cpp" when it doesn't even seem consistent with the rest of the language. I mean, every single other way, parenthesis without letters before them mean "expression". If I see (asdfgh), it means to me "the value of the variable asdfgh".... but if I see (asdfgh) 1, I have to realize this means "1 as a asdfgh". Now, truthfully, the new method has a problem in conformity itself, in that cast(asdfgh) 1 still looks a bit odd in that no other C/D code is like that..... but it is worlds better to me than the old method, because it makes it clearer that it's *doing something* and not just a silly expression. So, to me, cast(asdfgh) "feels" more like C than even the (asdfgh) I'm used to. You don't have to agree... but, don't think it's programming at the "mercy" of anyone - unless you are going to tell me that there is not one thing you think is not *PERFECT* about C... otherwise, you were at the "mercy" of its designers as well just as much as you are now at the "mercy" of D's. But.... if you thought C is perfect, why would you be here? You can't have everything your way... because, it happens, sometimes we humans are wrong. We can't help it, it just happens. Sometimes I'm wrong, sometimes you're wrong... that's why we use groups of people to decide what is right, because if most people think one thing.... that is probably really what's right, and the others are wrong... in that case. But next time it might be the other way around. -[Unknown]
May 05 2004
Unknown W. Brackets wrote:While personally I am happy with the old syntax.... it did always say to me "not C-ish". I don't know how you can call it "like C/Cpp" when it doesn't even seem consistent with the rest of the language.Every comparison will mostly result in that kind of conclusion.I mean, every single other way, parenthesis without letters before them mean "expression". If I see (asdfgh), it means to me "the value of the variable asdfgh".... but if I see (asdfgh) 1, I have to realize this means "1 as a asdfgh".n/cNow, truthfully, the new method has a problem in conformity itself, in that cast(asdfgh) 1 still looks a bit odd in that no other C/D code is like that..... but it is worlds better to me than the old method, because it makes it clearer that it's *doing something* and not just a silly expression. So, to me, cast(asdfgh) "feels" more like C than even the (asdfgh) I'm used to.1) cast(foo) looks like a function call; like a scripting language 2) Within normal statements, I have never seen a keyword used together with paranthesis.You don't have to agree... but, don't think it's programming at the "mercy" of anyone - unless you are going to tell me that there is not one thing you think is not *PERFECT* about C... otherwise, you were at the "mercy" of its designers as well just as much as you are now at the "mercy" of D's.Normally, standards are steady and not redefined in a weekly period.But.... if you thought C is perfect, why would you be here?Some enhancements of D (to C) make hacks faster and even more dirty, which is good. Although I miss bit fields and define statements, I may still code with freedom and close to my old C style. But that seems to be in a state of erosion.You can't have everything your way... because, it happens, sometimes we humans are wrong. We can't help it, it just happens. Sometimes I'm wrong, sometimes you're wrong... that's why we use groups of people to decide what is right, because if most people think one thing.... that is probably really what's right, and the others are wrong... in that case. But next time it might be the other way around.Condescending, thanks.
May 05 2004
Good point. As I've said many times in the past, I'd prefer cast(type, expr) On the plus side, however, it's relatively easy to disambiguate a cast from a function call simply because it uses the keyword cast. This may be used by both compilers and syntax-highlighting.Now, truthfully, the new method has a problem in conformity itself, in that cast(asdfgh) 1 still looks a bit odd in that no other C/D code is like that..... but it is worlds better to me than the old method, because it makes it clearer that it's *doing something* and not just a silly expression.> So, to me, cast(asdfgh) "feels" more like C than even the (asdfgh) I'm > used to. 1) cast(foo) looks like a function call; like a scripting language2) Within normal statements, I have never seen a keyword used together with paranthesis.True. But there isn't a standard yet, is there? We're pre-1.0. So what's your point?You don't have to agree... but, don't think it's programming at the "mercy" of anyone - unless you are going to tell me that there is not one thing you think is not *PERFECT* about C... otherwise, you were at the "mercy" of its designers as well just as much as you are now at the "mercy" of D's.Normally, standards are steady and not redefined in a weekly period.If you open the door ...You can't have everything your way... because, it happens, sometimes we humans are wrong. We can't help it, it just happens. Sometimes I'm wrong, sometimes you're wrong... that's why we use groups of people to decide what is right, because if most people think one thing.... that is probably really what's right, and the others are wrong... in that case. But next time it might be the other way around.Condescending, thanks.
May 05 2004
Matthew wrote:Why the paranthesis? Why wouldn't a syntax like this be applicable? Doesnt it look more like C/Cpp? -> doob = cast int myVar;As I've said many times in the past, I'd prefer cast(type, expr)So, to me, cast(asdfgh) "feels" more like C than even the (asdfgh) I'm used to.1) cast(foo) looks like a function call; like a scripting language
May 05 2004
Chr. Grade wrote:Matthew wrote:Nostalgia maybe? I think the parentheses make it more clear what is going on. And the *'s could get cluttered. doob = cast int * myVar; vs. doob = cast(int*) myVar; I prefer the later. I usually avoid pointers. Hopefully, my example isn't nonsense. :) -- Justin (a/k/a jcc7) http://jcc_7.tripod.com/d/Why the paranthesis? Why wouldn't a syntax like this be applicable? Doesnt it look more like C/Cpp? -> doob = cast int myVar;As I've said many times in the past, I'd prefer cast(type, expr)So, to me, cast(asdfgh) "feels" more like C than even the (asdfgh) I'm used to.1) cast(foo) looks like a function call; like a scripting language
May 05 2004
Chr. Grade wrote:Unknown W. Brackets wrote: 1) cast(foo) looks like a function call; like a scripting languageSo does if(true). Scary. But you can always use: int i = cast (int) otherVariable;2) Within normal statements, I have never seen a keyword used together with paranthesis.I can take your statement two ways; you either mean that you don't see (keyword) except for casting, or you don't see keyword(). The latter is probably not it when you consider if, while, and the like. As far as the former, maybe so.... but, what about casting to a class? That's not a keyword, and it can get confusing like that.Normally, standards are steady and not redefined in a weekly period.Yet that is really what development is, isn't it? I was under the impression that D was under development... and I haven't seen it be redefined every week.... But, Mozilla seems not to follow standards by your definition either. Their internal functions change, they redefine what css properties should do, and how the dom should be handled... not only weekly, but daily.I'm sorry if you're disenchanted with the changes being made. I on the other hand am happy with them, and would call your "erosion" instead development. I'm sure a happy medium can be achieved, though.But.... if you thought C is perfect, why would you be here?Some enhancements of D (to C) make hacks faster and even more dirty, which is good. Although I miss bit fields and define statements, I may still code with freedom and close to my old C style. But that seems to be in a state of erosion.You're welcome. Maybe you think it's condescending but some people don't want to realize that it is indeed the case.... even if they say, "of course - you're patronizing me, we all know that." I live in California... I see this kind of thing every day. Please, don't be so quick to call me on being "condescending" and actually just read it and take it at face value. -[Unknown]You can't have everything your way... because, it happens, sometimes we humans are wrong. We can't help it, it just happens. Sometimes I'm wrong, sometimes you're wrong... that's why we use groups of people to decide what is right, because if most people think one thing.... that is probably really what's right, and the others are wrong... in that case. But next time it might be the other way around.Condescending, thanks.
May 05 2004
Chr. Grade wrote:Either D feels like C/Cpp or it doesn't.I certainly hope it don't. Lars Ivar Igesund
May 05 2004
Chr. Grade wrote:Either D feels like C/Cpp or it doesn't.Ethereal concepts like 'feeling' are rarely absolute. :)Such thing obscures the relation to C/Cpp and puts up an obstacle for frist timers. C style casts will be cut out first. And what's next? How many times will I have to partially rewrite my code. Over and over? Every time a new compiler version is released? Programming at Walter's and the D-community's mercy. So, that's the downside of D?That's the downside of using a beta compiler for a beta language. The upside, of course, is the chance to change the language for the better.And where's the C hardcore faction?Using C, probably. :) -- andy
May 05 2004
"Chr. Grade" <tickle everymail.net> wrote in message news:c7bfsq$22rp$1 digitaldaemon.com...Either D feels like C/Cpp or it doesn't. Such thing obscures the relation to C/Cpp and puts up an obstacle for frist timers. C style casts will be cut out first. And what's next? How many times will I have to partially rewrite my code. Over and over? Every time a new compiler version is released?I hear you, which is why I put this question here. Also, there are maybe a hundred or so casts in the phobos source that needs fixing, so I have to modify my own code, too. On the other hand, it's a trivial change, I can do a hundred fixes in a few minutes. Just past 'cast' in before the parentheses.Programming at Walter's and the D-community's mercy. So, that's the downside of D? And where's the C hardcore faction?I should also point out that the C++ community has also declared C casts as obsolete (though still in the language) and replaced with static_cast and related.
May 05 2004
C-style cast is informally deprecated even in C++, where you should use template-like casts static_cast, dynamic_cast and reinterpret_cast, to which D cast is similar enough. Having said that, D has a few other points where C programmers may stumble, and many many points left from C where non-C programmers will. This cannot be changed. And the differences from C are largely of semantical and not syntactical nature, and may cause some headache at first but prove very advantageous later on. Having also seen that some otherwise legal expressions get rejected because they "look like" a C-style cast, but in fact aren't, makes me vote to remove C-style casts. Now, it's already happened. And is one more word "cast" that much of a problem? -eye Chr. Grade schrieb:The closer D will remain related to C and Cpp, the more likely people are willing to have a closer look at D and programm with it and switch to it. D has to be intuitive for D-newbies. I merely tried D because it looked and felt so familiar. I'd be more than disencouraged if C/Cpp style casts were missing, because I'm simply used to them; I like them.
May 16 2004
Walter wrote:What do people think about first deprecating, then removing, the C style cast?+1 D-style casts: great. C-style casts: lame.
May 05 2004
"Walter" <newshound digitalmars.com> wrote in message news:c7b6vn$1o0h$1 digitaldaemon.com...What do people think about first deprecating, then removing, the C style cast?+1
May 05 2004
What do people think about first deprecating, then removing, the C style cast?let it go, I had to get used to the new C++ casts, so D casts should be no problem
May 05 2004
Do it! No question. "Walter" <newshound digitalmars.com> wrote in message news:c7b6vn$1o0h$1 digitaldaemon.com...Currently, D supports C style casts: (type)expression as well as D style casts: cast(type)expression The C style casts are tricky to parse right, and I think will cause increasing problems down the road due to the syntactical ambiguities with it. The D style cast has no such problems, and it has the advantage of being greppable (as some programming styles consider an explicit cast to be a bug, and being able to find and check them all to be a Good Thing). What do people think about first deprecating, then removing, the C style cast?
May 05 2004
"Walter" <newshound digitalmars.com> wrote in message news:c7b6vn$1o0h$1 digitaldaemon.com...Currently, D supports C style casts: (type)expression as well as D style casts: cast(type)expressionI should also confess that I'm looking into implementing things like: a = (int == T) ? c : d; // is T an alias for type int? which will cause even more parser grief disambiguating them from C style casts. Essentially, I'm looking at the possibility of a type being an expression. The utility of it is to be able to write simpler and more straightforward generic code, without resorting to forests of inscrutable template specializations.
May 05 2004
Walter wrote:I should also confess that I'm looking into implementing things like: a = (int == T) ? c : d; // is T an alias for type int? which will cause even more parser grief disambiguating them from C style casts. Essentially, I'm looking at the possibility of a type being an expression. The utility of it is to be able to write simpler and more straightforward generic code, without resorting to forests of inscrutable template specializations.My head is spinning: static assert(X inherits Y); if (X has method void foo(int y, float z)) { ... } else { ... } -- andy
May 05 2004
"Andy Friesen" <andy ikagames.com> wrote in message news:c7brvh$2pdu$1 digitaldaemon.com...Walter wrote:inscrutableI should also confess that I'm looking into implementing things like: a = (int == T) ? c : d; // is T an alias for type int? which will cause even more parser grief disambiguating them from C style casts. Essentially, I'm looking at the possibility of a type being an expression. The utility of it is to be able to write simpler and more straightforward generic code, without resorting to forests ofI was thinking that could be done with: static assert(cast(Y)X);template specializations.My head is spinning: static assert(X inherits Y);if (X has method void foo(int y, float z)) { ... } else { ... }That's a lot further down that road <g>.
May 05 2004
Walter wrote:I should also confess that I'm looking into implementing things like: a = (int == T) ? c : d; // is T an alias for type int? which will cause even more parser grief disambiguating them from C style casts. Essentially, I'm looking at the possibility of a type being an expression. The utility of it is to be able to write simpler and more straightforward generic code, without resorting to forests of inscrutable template specializations.So does that means we could store a type in a variable! That's the solution to the var_args problem. -- Julio César Carrascal Urquijo http://jcesar.f2o.org/ -----BEGIN GEEK CODE BLOCK----- Version: 3.12 GCS$ d- s+:+ a-- C++> ULS++ P++ L+> !E W+++ N+ o? K? w++> O--- M V? PS+ PE Y+ PGP t+ 5- X+++ R- tv+(++) b++> DI! D++> G e+> h-- r- y+ ------END GEEK CODE BLOCK------
May 06 2004
Walter wrote:I should also confess that I'm looking into implementing things like: a = (int == T) ? c : d; // is T an alias for type int? which will cause even more parser grief disambiguating them from C style casts. Essentially, I'm looking at the possibility of a type being an expression. The utility of it is to be able to write simpler and more straightforward generic code, without resorting to forests of inscrutable template specializations.Hey... I remember talking about something along these lines some time ago. Hope to see it happen. This combined with the 'variant' type proposed elsewhere on the NG would make for one fine system, methinks. -C. Sauls -Invironz
May 06 2004
Walter wrote: > I should also confess that I'm looking into implementing things like:a = (int == T) ? c : d; // is T an alias for type int? which will cause even more parser grief disambiguating them from C style casts. Essentially, I'm looking at the possibility of a type being an expression. The utility of it is to be able to write simpler and more straightforward generic code, without resorting to forests of inscrutable template specializations.I like this! But why not use the same method to avoid the ambiguity as for cast? a= (type(int) == type(T)) ? c : d; or (maybe better) a= int.type == T.type ? c : d; or perhaps a= T.typeEquals(int) ? c : d; or something like that? Hauke
May 09 2004
"Hauke Duden" <H.NS.Duden gmx.net> wrote in message news:c7l3qr$1i5n$1 digitaldaemon.com...Walter wrote: > I should also confess that I'm looking into implementing things like:inscrutablea = (int == T) ? c : d; // is T an alias for type int? which will cause even more parser grief disambiguating them from C style casts. Essentially, I'm looking at the possibility of a type being an expression. The utility of it is to be able to write simpler and more straightforward generic code, without resorting to forests ofSomething like that will have to be done. For example, is: foo*fp[] an expression or a type? It's ambiguous. There'll have to be something like what you propose. Probably 'typename' instead of 'type', as 'type' appears too often as a variable name.template specializations.I like this! But why not use the same method to avoid the ambiguity as for cast? a= (type(int) == type(T)) ? c : d;or (maybe better) a= int.type == T.type ? c : d;Parsing ambiguity problems.or perhaps a= T.typeEquals(int) ? c : d; or something like that?I think typename(int) will parse easilly and so will work best.
May 11 2004
Could this fall into the domain of typeof() perhaps? That's already in the language, and likely to be a common companion to whatever becomes this. Or at least that's what I see. a = typeof(int) == typeof(T) ? c : d; -C. Sauls -Invironz Walter wrote:"Hauke Duden" <H.NS.Duden gmx.net> wrote in message news:c7l3qr$1i5n$1 digitaldaemon.com...Walter wrote: > I should also confess that I'm looking into implementing things like:inscrutablea = (int == T) ? c : d; // is T an alias for type int? which will cause even more parser grief disambiguating them from C style casts. Essentially, I'm looking at the possibility of a type being an expression. The utility of it is to be able to write simpler and more straightforward generic code, without resorting to forests ofSomething like that will have to be done. For example, is: foo*fp[] an expression or a type? It's ambiguous. There'll have to be something like what you propose. Probably 'typename' instead of 'type', as 'type' appears too often as a variable name.template specializations.I like this! But why not use the same method to avoid the ambiguity as for cast? a= (type(int) == type(T)) ? c : d;or (maybe better) a= int.type == T.type ? c : d;Parsing ambiguity problems.or perhaps a= T.typeEquals(int) ? c : d; or something like that?I think typename(int) will parse easilly and so will work best.
May 11 2004
Won't work as an argument to typeof, because typeof(foo[]) is ambiguous.
May 17 2004
Walter wrote:Currently, D supports C style casts: (type)expression as well as D style casts: cast(type)expression The C style casts are tricky to parse right, and I think will cause increasing problems down the road due to the syntactical ambiguities with it. The D style cast has no such problems, and it has the advantage of being greppable (as some programming styles consider an explicit cast to be a bug, and being able to find and check them all to be a Good Thing). What do people think about first deprecating, then removing, the C style cast?I'm definitely in favor of this. Let's get rid of those C-style casts. -- Justin (a/k/a jcc7) http://jcc_7.tripod.com/d/
May 05 2004
+1 In article <c7b6vn$1o0h$1 digitaldaemon.com>, Walter says...Currently, D supports C style casts: (type)expression as well as D style casts: cast(type)expression The C style casts are tricky to parse right, and I think will cause increasing problems down the road due to the syntactical ambiguities with it. The D style cast has no such problems, and it has the advantage of being greppable (as some programming styles consider an explicit cast to be a bug, and being able to find and check them all to be a Good Thing). What do people think about first deprecating, then removing, the C style cast?
May 05 2004
Walter wrote:Currently, D supports C style casts: (type)expression as well as D style casts: cast(type)expression The C style casts are tricky to parse right, and I think will cause increasing problems down the road due to the syntactical ambiguities with it. The D style cast has no such problems, and it has the advantage of being greppable (as some programming styles consider an explicit cast to be a bug, and being able to find and check them all to be a Good Thing). What do people think about first deprecating, then removing, the C style cast?Good idea except for the deprecating part. C-style casts have been informally deprecated for months. Just remove them now. Certainly, at the very least, remove them before 1.0. Russ
May 05 2004
In article <c7bqka$2mge$1 digitaldaemon.com>, Russ Lewis says...Walter wrote:[Warning: 1st post] I agree with Russ and the others who wish to see the C-Style casts removed. Otherwise there's going to be a ton of code written that'll have a mixed casting style, which IMHO will only make the code written harder to read and to maintained. It's really better to have just the one way (the D-way), and "keep it simple." (Note: I've been following this forum for nearly 6 months, and I really like the way everyone here works so well together to build a better C/C++ like Langauge. I think "D" is going to be a much better programming Langauge because of it!)Currently, D supports C style casts: (type)expression as well as D style casts: cast(type)expression The C style casts are tricky to parse right, and I think will cause increasing problems down the road due to the syntactical ambiguities with it. The D style cast has no such problems, and it has the advantage of being greppable (as some programming styles consider an explicit cast to be a bug, and being able to find and check them all to be a Good Thing). What do people think about first deprecating, then removing, the C style cast?Good idea except for the deprecating part. C-style casts have been informally deprecated for months. Just remove them now. Certainly, at the very least, remove them before 1.0. Russ
May 06 2004
"Walter" <newshound digitalmars.com> wrote in message news:c7b6vn$1o0h$1 digitaldaemon.com...Currently, D supports C style casts: (type)expression as well as D style casts: cast(type)expressioni would prefer somthing like... (cast type expresson) (expresion as type) at least then the expresion and the type are more clearly bracketed together and much easier on the eye imo. chris
May 05 2004
I'll never be able to program again. But then the doco already made me think I had to use cast(). Fire away. "Walter" <newshound digitalmars.com> wrote in message news:c7b6vn$1o0h$1 digitaldaemon.com...Currently, D supports C style casts: (type)expression as well as D style casts: cast(type)expression The C style casts are tricky to parse right, and I think will cause increasing problems down the road due to the syntactical ambiguities with it. The D style cast has no such problems, and it has the advantage ofbeinggreppable (as some programming styles consider an explicit cast to be abug,and being able to find and check them all to be a Good Thing). What do people think about first deprecating, then removing, the C style cast?
May 06 2004
Walter wrote:What do people think about first deprecating, then removing, the C style cast?I guess people should start updating there documentation now if they are using any old casts. Do you know any wiki pages that use C casts? -- -Anderson: http://badmama.com.au/~anderson/
May 06 2004
On Wed, 5 May 2004 10:04:08 -0700, "Walter" <newshound digitalmars.com> wrote:Currently, D supports C style casts: (type)expression as well as D style casts: cast(type)expression The C style casts are tricky to parse right, and I think will cause increasing problems down the road due to the syntactical ambiguities with it. The D style cast has no such problems, and it has the advantage of being greppable (as some programming styles consider an explicit cast to be a bug, and being able to find and check them all to be a Good Thing). What do people think about first deprecating, then removing, the C style cast?do it ... and finally resolve that persistant BUG int main( char[][] args ) { int a; int b a = args.length; b = (a); return 0; } //casttest.d(7): semicolon expected, not 'a'
May 06 2004
In DMD 0.89, the following: int so = (schar*)slice - (schar*)string; The compiler suggests: "C style cast deprecated, use cast(*schar)(slice)" That doesn't work, but the following does: int so = cast(schar*)slice - cast(schar*)string; Any danger in ignoring the compiler here? Should the compiler give a better message? BTW, this is Vathix's string.d BA
May 17 2004
"Brad Anderson" <brad sankaty.dot.com> wrote in message news:c8bsf6$1rvi$1 digitaldaemon.com...In DMD 0.89, the following: int so = (schar*)slice - (schar*)string; The compiler suggests: "C style cast deprecated, use cast(*schar)(slice)" That doesn't work, but the following does: int so = cast(schar*)slice - cast(schar*)string; Any danger in ignoring the compiler here? Should the compiler give abettermessage?No. Yes. <g>
May 24 2004