digitalmars.D - Re: new DIP5: Properties 2
- bearophile <bearophileHUGS lycos.com> Jul 28 2009
- Bill Baxter <wbaxter gmail.com> Jul 28 2009
- bearophile <bearophileHUGS lycos.com> Jul 28 2009
- bearophile <bearophileHUGS lycos.com> Jul 28 2009
- Bill Baxter <wbaxter gmail.com> Jul 28 2009
Bill Baxter:Now we may not want to go so hog wild putting this and that everywhere, but if we did we could get rid of 19 keywords right there, and add property also without adding a new keyword.
Glad to see I'm not the only one to think like this :-) Later more semantic attributes can be added, for example to express things that the compiler can use to parallelize code better, to know about pointer aliasing, to tell the compiler what asm functions can be inlined (currently done with a pragma in LDC), etc. What syntax do you want to use when you want more than one attribute? something1 somethingelse ... Bye, bearophile
Jul 28 2009
On Tue, Jul 28, 2009 at 11:12 AM, bearophile<bearophileHUGS lycos.com> wrot= e:Bill Baxter:Now we may not want to go so hog wild putting this and that everywhere, but if we did we could get rid of 19 keywords right there, and add property also without adding a new keyword.
Glad to see I'm not the only one to think like this :-) Later more semantic attributes can be added, for example to express thing=
er aliasing, to tell the compiler what asm functions can be inlined (curren= tly done with a pragma in LDC), etc.What syntax do you want to use when you want more than one attribute? something1 somethingelse ...
I don't know. I'm actually not too up on how these things are used in the languages where they exist (just Java, Python, and C#?). It just seems like a good idea to solve a more general problem if possible. And when someone reminded us that "deprecated" is a keyword, that set me off. Something else that occurred to me while reading the keyword list is that "switch" is a horrible keyword hog. Three keywords just for that one construct! If D didn't have a switch statement today and were looking to add one, somehow I doubt that there would be sufficient support for dedicating three whole keywords to the thing. Switch is a monstrosity pretty much any way you look at it. Sh had the right idea there. Is "case" really necessary there? Some syntax should suffice I would thing. And "default" is probably the world's most useless keyword. Why not "else:" or "*:" instead of introducing a whole new keyword? --bb
Jul 28 2009
Bill Baxter:Switch is a monstrosity pretty much any way you look at it. Sh had the right idea there. Is "case" really necessary there? Some syntax should suffice I would thing. And "default" is probably the world's most useless keyword. Why not "else:" or "*:" instead of introducing a whole new keyword?
Case of Pascal is better (2 keywords where "of" isn't that useful, begin-end are optional if you want more than one instruction, Pascal isn't case-sensitive): Case X of 1: Begin ... End; 2 .. 10: Begin ... End; ... Else Begin ... End; End; {CASE} But D is backward compatible with C (unlike languages like Scala, that eventually D will need to take a look at), so this is an academic topic. Bye, bearophile
Jul 28 2009
Bill Baxter:Changing the keywords used in a switch would be a very mechanical transformation, like changing typedef to alias everywhere it appears in C code you're translating.
Once you have changed the keyword used in the case/switch, then you (and me) probably want to fix other problems of switch (fall through). Recently here I have suggested the creation of a small tool (written in Python, not in D) like 2to3 (used to convert Python2 to Python3) to convert C to D :-) I don't know how much long such program may become (2to3 uses a parser of the std lib). Bye, bearophile
Jul 28 2009
On Tue, Jul 28, 2009 at 12:01 PM, bearophile<bearophileHUGS lycos.com> wrot= e:Bill Baxter:Switch is a monstrosity pretty much any way you look at it. =A0Sh had th=
idea there. =A0Is "case" really necessary there? =A0Some syntax should suffice I would thing. =A0And "default" is probably the world's most useless keyword. =A0Why not "else:" or "*:" instead of introducing a whole new keyword?
Case of Pascal is better (2 keywords where "of" isn't that useful, begin-=
ensitive):Case X of =A01: Begin =A0 =A0 =A0 =A0... =A0 =A0 =A0End; =A02 .. 10: Begin =A0 =A0 =A0 =A0... =A0 =A0 =A0End; =A0... =A0Else Begin =A0 =A0 =A0 =A0 ... =A0 =A0 =A0 End; End; {CASE} But D is backward compatible with C (unlike languages like Scala, that ev=
Except that it's very much not backwards compatible with C syntax in constructs that are very frequent in C: typedef/alias, #define. Changing the keywords used in a switch would be a very mechanical transformation, like changing typedef to alias everywhere it appears in C code you're translating. --bb
Jul 28 2009