digitalmars.D - __traits so long and ugly, what about ::?
- Ary Manzana (18/18) Mar 30 2011 I think :: is not used in the language.
- David Nadlinger (6/6) Mar 30 2011 You are not the only one to find __traits ugly – although not directly...
- Ary Manzana (7/13) Mar 30 2011 David, thanks for the answer. I am aware of that proposal, but I don't
- Nick Sabalausky (5/19) Mar 30 2011 I've always felt the meta namespace should be member-call syntax:
- KennyTM~ (15/33) Mar 30 2011 -1.
- Alix Pexton (6/7) Mar 30 2011 The first thing it reminded me of was Lua, where a single colon makes
- KennyTM~ (10/17) Mar 30 2011 That is almost like UFCS in D.
- Ary Manzana (6/27) Mar 30 2011 Look, metaprogramming in Ruby is a relatively advanced part of the
- bearophile (4/5) Mar 30 2011 I agree. On the other hand is the :: syntax easy compared to a "meta." n...
- Andrej Mitrovic (1/1) Mar 30 2011 How about not inventing new syntaxes? Leave that to C++7xFF.
- bearophile (4/5) Mar 30 2011 Sorry for not being clear, by "alternative syntaxes" I meant something l...
- KennyTM~ (16/50) Mar 30 2011 We're talking about __traits, a feature for compile-time reflection
- Ary Manzana (10/10) Mar 30 2011 I just hate it when you have to write too much to get simple things
- KennyTM~ (13/23) Mar 30 2011 How often do you really needs feature in __traits? I've grepped my code
- Jonathan M Davis (8/45) Mar 30 2011 I use __traits(compiles, ) all the time, and a few of the others in __tr...
- KennyTM~ (3/32) Mar 30 2011 PS. I don't mean to push this proposal. This is just to show that
- Andrei Alexandrescu (12/22) Mar 30 2011 I understand and to a good extent agree with the sentiment.
- KennyTM~ (3/31) Mar 30 2011 I think the GSoC group and language feature discussion group should be
- Andrei Alexandrescu (6/42) Mar 30 2011 That makes sense, but I'd rather encourage our limited regular
- bearophile (5/7) Mar 31 2011 Regarding D/Phobos feature discussions, they don't damage the summer of ...
- Andrei Alexandrescu (3/9) Mar 31 2011 They do share the same time budget.
- Steven Schveighoffer (8/18) Mar 31 2011 So don't read/respond to the posts. I think any discouragement for open...
- Andrei Alexandrescu (7/25) Mar 31 2011 Well you know it's considerably less simpler than that. Besides, I
- Steven Schveighoffer (9/35) Mar 31 2011 That's a better statement. I just don't think such "unimportant"
- Bruno Medeiros (7/36) Apr 07 2011 Yeah, kinda, but the thing is that such discussions are often done
- spir (9/12) Mar 31 2011 Pleased to read that :-) I've had this sentiment for a while as well. I'...
- Jacob Carlborg (5/58) Mar 31 2011 In Ruby it would just be: S.hasMember("m") and "hasMember" would just be...
- Jacob Carlborg (5/39) Mar 31 2011 Yes, because there is nothing special with how the meta information is
- spir (11/54) Mar 30 2011 D is not C++. D precisely exists to make things differently, ie its own ...
- Jacob Carlborg (6/50) Mar 31 2011 I think think this is a valid reason. D does many things differently
- Alix Pexton (20/38) Mar 30 2011 Hmn, interesting idea! I noticed, however, that the "foo" and "bar" in
- Alix Pexton (2/51) Mar 30 2011 Damn I type slow ><
- spir (7/24) Mar 30 2011 Waow, this /is/ syntactic sugar ;-)
- Jacob Carlborg (4/22) Mar 31 2011 I like it.
- so (5/23) Mar 31 2011 I agree it is a problem (a small one) but i don't believe it deserves a ...
- Kagamin (5/6) Mar 31 2011 hasMember!(S, "m")
- Ary Manzana (3/9) Mar 31 2011 Ah, so then I change it to:
- Jonathan M Davis (6/14) Mar 31 2011 And hasMember!(S, "m") is actually consistent with the rest of the langu...
- Alix Pexton (17/31) Apr 01 2011 I thought the :: syntax seemed pretty intuitive (keystroke savings never...
- Don (6/47) Apr 01 2011 The chief problem is that there is no way to hide __traits(compiles).
I think :: is not used in the language. In a recent article about D I saw: mixin(__traits(identifier, T) ~ " " ~ to!string(tolower(__traits(identifier, T)[0])) ~ __traits(identifier, T)[1..$] ~ ";"); What if foo::bar were an alias for __traits(foo, bar) ? The code would look like this: mixin(T::identifier ~ " " ~ to!string(tolower(T::identifier[0])) ~ T::identifier[1..$] ~ ";"); What do you think? Another uses: __traits(int, isArithmetic) ==> int::isArithmetic __traits(C, isAbstractClass) ==> C::isAbstractClass __traits(hasMember, S, "m") ==> S::hasMember("m") Well, you get the idea... :: might be applied to other compile time uses, but I just came up with this...
Mar 30 2011
You are not the only one to find __traits ugly – although not directly related to your question, it has been proposed several times to ditch is(typeof()) and __traits and replace them with a magic »meta« namespace. There is even a bug report about it: http://d.puremagic.com/issues/show_bug.cgi?id=3702 David
Mar 30 2011
On 3/30/11 4:32 PM, David Nadlinger wrote:You are not the only one to find __traits ugly – although not directly related to your question, it has been proposed several times to ditch is(typeof()) and __traits and replace them with a magic »meta« namespace. There is even a bug report about it: http://d.puremagic.com/issues/show_bug.cgi?id=3702 DavidDavid, thanks for the answer. I am aware of that proposal, but I don't like it because it's not very readble. You have to read "meta isArithmetic int", kind of like how yoda speaks, but in the other case, "int::isArithmetic" is much more natural and shorter and nicer. I'm just suggesting a syntax for accessing compile-time things. It seems :: is unused...
Mar 30 2011
"Ary Manzana" <ary esperanto.org.ar> wrote in message news:in0169$5sb$1 digitalmars.com...On 3/30/11 4:32 PM, David Nadlinger wrote:I've always felt the meta namespace should be member-call syntax: int.meta.whatever Your suggestion is a nice shortcut to that, though.You are not the only one to find __traits ugly - although not directly related to your question, it has been proposed several times to ditch is(typeof()) and __traits and replace them with a magic »meta« namespace. There is even a bug report about it: http://d.puremagic.com/issues/show_bug.cgi?id=3702 DavidDavid, thanks for the answer. I am aware of that proposal, but I don't like it because it's not very readble. You have to read "meta isArithmetic int", kind of like how yoda speaks, but in the other case, "int::isArithmetic" is much more natural and shorter and nicer. I'm just suggesting a syntax for accessing compile-time things. It seems :: is unused...
Mar 30 2011
On Mar 31, 11 03:28, Ary Manzana wrote:I think :: is not used in the language. In a recent article about D I saw: mixin(__traits(identifier, T) ~ " " ~ to!string(tolower(__traits(identifier, T)[0])) ~ __traits(identifier, T)[1..$] ~ ";"); What if foo::bar were an alias for __traits(foo, bar) ? The code would look like this: mixin(T::identifier ~ " " ~ to!string(tolower(T::identifier[0])) ~ T::identifier[1..$] ~ ";"); What do you think? Another uses: __traits(int, isArithmetic) ==> int::isArithmetic __traits(C, isAbstractClass) ==> C::isAbstractClassYou've got the order wrong.__traits(hasMember, S, "m") ==> S::hasMember("m") Well, you get the idea... :: might be applied to other compile time uses, but I just came up with this...-1. This is confusing as :: is used to separate scopes in C++ (and PHP too). e.g. struct A { int x; bool isSame(const A other) pure const { return x == other.x; } } void main () { A a = A(2), b = A(2); assert ( a.isSame(b)); // ok assert (! a::isSame(b)); // ??? } (How about that 'meta' namespace proposal? meta.hasMember(S, "m") )
Mar 30 2011
On 30/03/2011 20:45, KennyTM~ wrote:This is confusing as :: is used to separate scopes in C++ (and PHP too).The first thing it reminded me of was Lua, where a single colon makes the left hand side into the first argument of the function on the right. foo:bar(x) ==> bar.(foo, x) So it felt kinda familiar to me ^^ A...
Mar 30 2011
On Mar 31, 11 04:19, Alix Pexton wrote:On 30/03/2011 20:45, KennyTM~ wrote:That is almost like UFCS in D. int foo(string x, int y) { return x.length - y; } assert (foo("testing", 3) == 4); assert ("testing".foo(3) == 4); But OP's proposal is restricted to __traits only. __traits is a relatively advanced part of the language, plus many of its features has already been exposed via the library std.traits, e.g. std.traits.hasMember!(S, "m"), I don't think it really needs a very short syntax.This is confusing as :: is used to separate scopes in C++ (and PHP too).The first thing it reminded me of was Lua, where a single colon makes the left hand side into the first argument of the function on the right. foo:bar(x) ==> bar.(foo, x) So it felt kinda familiar to me ^^ A...
Mar 30 2011
On 3/30/11 5:52 PM, KennyTM~ wrote:On Mar 31, 11 04:19, Alix Pexton wrote:Look, metaprogramming in Ruby is a relatively advanced part of the language. And you know why it is heavily used and everyone can jump and start using it in a matter of seconds and build the most amazing things? Because it's very, very, very, (add 1000 very words here), very easy to use. Why make *anything* hard to use if you can do it in an easier way?On 30/03/2011 20:45, KennyTM~ wrote:That is almost like UFCS in D. int foo(string x, int y) { return x.length - y; } assert (foo("testing", 3) == 4); assert ("testing".foo(3) == 4); But OP's proposal is restricted to __traits only. __traits is a relatively advanced part of the language, plus many of its features has already been exposed via the library std.traits, e.g. std.traits.hasMember!(S, "m"), I don't think it really needs a very short syntax.This is confusing as :: is used to separate scopes in C++ (and PHP too).The first thing it reminded me of was Lua, where a single colon makes the left hand side into the first argument of the function on the right. foo:bar(x) ==> bar.(foo, x) So it felt kinda familiar to me ^^ A...
Mar 30 2011
Ary Manzana:Why make *anything* hard to use if you can do it in an easier way?I agree. On the other hand is the :: syntax easy compared to a "meta." namespace? The meta name is more readable. I suggest to try to invent few more alternative syntaxes before choosing. Bye, bearophile
Mar 30 2011
How about not inventing new syntaxes? Leave that to C++7xFF.
Mar 30 2011
Andrej Mitrovic:How about not inventing new syntaxes? Leave that to C++7xFF.Sorry for not being clear, by "alternative syntaxes" I meant something like the "meta" namespace too. Bye, bearophile
Mar 30 2011
On Mar 31, 11 06:32, Ary Manzana wrote:On 3/30/11 5:52 PM, KennyTM~ wrote:We're talking about __traits, a feature for compile-time reflection where most of its capability is already wrapped up to std.traits. It isn't comparable with the whole metaprogramming capability in another language. You know, metaprogramming is also heavily used in D, because of a sensible template system, mixins and CTFE, not __traits.On Mar 31, 11 04:19, Alix Pexton wrote:Look, metaprogramming in Ruby is a relatively advanced part of the language. And you know why it is heavily used and everyone can jump and start using it in a matter of seconds and build the most amazing things? Because it's very, very, very, (add 1000 very words here), very easy to use.On 30/03/2011 20:45, KennyTM~ wrote:That is almost like UFCS in D. int foo(string x, int y) { return x.length - y; } assert (foo("testing", 3) == 4); assert ("testing".foo(3) == 4); But OP's proposal is restricted to __traits only. __traits is a relatively advanced part of the language, plus many of its features has already been exposed via the library std.traits, e.g. std.traits.hasMember!(S, "m"), I don't think it really needs a very short syntax.This is confusing as :: is used to separate scopes in C++ (and PHP too).The first thing it reminded me of was Lua, where a single colon makes the left hand side into the first argument of the function on the right. foo:bar(x) ==> bar.(foo, x) So it felt kinda familiar to me ^^ A...Why make *anything* hard to use if you can do it in an easier way?Is meta.hasMember(S, "m") or even import std.traits; ... hasMember!(S, "m") really that hard to use? I think the 'meta' namespace is enough. 'A::B' is too much for such a low-level feature.
Mar 30 2011
I just hate it when you have to write too much to get simple things done. Does this type have a member? Current approach: 1. import std.traits; 2. invoke hasMember!(S, "m") Another approach: 1. I have the type, let's ask it: S::hasMember("m") Map's thought to code. My problem is that when you start using D's cool features you end up with a really hard to understand and obscure code...
Mar 30 2011
On Mar 31, 11 09:42, Ary Manzana wrote:I just hate it when you have to write too much to get simple things done. Does this type have a member? Current approach: 1. import std.traits; 2. invoke hasMember!(S, "m") Another approach: 1. I have the type, let's ask it: S::hasMember("m") Map's thought to code. My problem is that when you start using D's cool features you end up with a really hard to understand and obscure code...How often do you really needs feature in __traits? I've grepped my code which uses a lot of templates and CTFE, and it only appears in 2 lines else static if (__traits(isScalar, T)) { static if (__traits(compiles, T.init.re)) Therefore I oppose the use of :: just for __traits, because it's so rare. Now I have a counter-proposal, T::ident(x, y, z, ...) <=> ident!(T, x, y, z, ...) then hasMember can be invoked as import std.traits; ... S::hasMember("m") Isn't it better than reserving :: just for __traits?
Mar 30 2011
On 2011-03-30 19:38, KennyTM~ wrote:On Mar 31, 11 09:42, Ary Manzana wrote:I use __traits(compiles, ) all the time, and a few of the others in __traits, though I probably use std.traits more than __traits. I don't mind the meta proposal (__traits _is_ kind of ugly), but I _definitely_ don't like the :: proposal. I don't find it to be clear at all, and it's one more operator to remember. Not to mention, it might cause problems when porting C++ code. - Jonathan M DavisI just hate it when you have to write too much to get simple things done. Does this type have a member? Current approach: 1. import std.traits; 2. invoke hasMember!(S, "m") Another approach: 1. I have the type, let's ask it: S::hasMember("m") Map's thought to code. My problem is that when you start using D's cool features you end up with a really hard to understand and obscure code...How often do you really needs feature in __traits? I've grepped my code which uses a lot of templates and CTFE, and it only appears in 2 lines else static if (__traits(isScalar, T)) { static if (__traits(compiles, T.init.re)) Therefore I oppose the use of :: just for __traits, because it's so rare. Now I have a counter-proposal, T::ident(x, y, z, ...) <=> ident!(T, x, y, z, ...) then hasMember can be invoked as import std.traits; ... S::hasMember("m") Isn't it better than reserving :: just for __traits?
Mar 30 2011
On Mar 31, 11 10:38, KennyTM~ wrote:On Mar 31, 11 09:42, Ary Manzana wrote:PS. I don't mean to push this proposal. This is just to show that instead of using :: for __traits, there is a better alternative.I just hate it when you have to write too much to get simple things done. Does this type have a member? Current approach: 1. import std.traits; 2. invoke hasMember!(S, "m") Another approach: 1. I have the type, let's ask it: S::hasMember("m") Map's thought to code. My problem is that when you start using D's cool features you end up with a really hard to understand and obscure code...How often do you really needs feature in __traits? I've grepped my code which uses a lot of templates and CTFE, and it only appears in 2 lines else static if (__traits(isScalar, T)) { static if (__traits(compiles, T.init.re)) Therefore I oppose the use of :: just for __traits, because it's so rare. Now I have a counter-proposal, T::ident(x, y, z, ...) <=> ident!(T, x, y, z, ...) then hasMember can be invoked as import std.traits; ... S::hasMember("m") Isn't it better than reserving :: just for __traits?
Mar 30 2011
On 3/30/11 8:42 PM, Ary Manzana wrote:I just hate it when you have to write too much to get simple things done. Does this type have a member? Current approach: 1. import std.traits; 2. invoke hasMember!(S, "m") Another approach: 1. I have the type, let's ask it: S::hasMember("m") Map's thought to code. My problem is that when you start using D's cool features you end up with a really hard to understand and obscure code...I understand and to a good extent agree with the sentiment. However, right now GSoC with student proposals to attract and review, an undergoing Phobos proposal review, one or a couple more waiting in the queue, good progress in core areas (64 bit stabilization, rigorous deterministic destruction, important bug fixes, and to follow the immutability subsystem and shared libraries) I can't stop feeling many of such discussions do more harm than good. There's always a better way to express a frequent idiom, and we may as well adopt one later. But this is the time to act, and there's plenty to act on. Let's focus on getting real work done. This is the D Summer of Code. :o) Andrei
Mar 30 2011
On Mar 31, 11 11:24, Andrei Alexandrescu wrote:On 3/30/11 8:42 PM, Ary Manzana wrote:I think the GSoC group and language feature discussion group should be separated.I just hate it when you have to write too much to get simple things done. Does this type have a member? Current approach: 1. import std.traits; 2. invoke hasMember!(S, "m") Another approach: 1. I have the type, let's ask it: S::hasMember("m") Map's thought to code. My problem is that when you start using D's cool features you end up with a really hard to understand and obscure code...I understand and to a good extent agree with the sentiment. However, right now GSoC with student proposals to attract and review, an undergoing Phobos proposal review, one or a couple more waiting in the queue, good progress in core areas (64 bit stabilization, rigorous deterministic destruction, important bug fixes, and to follow the immutability subsystem and shared libraries) I can't stop feeling many of such discussions do more harm than good. There's always a better way to express a frequent idiom, and we may as well adopt one later. But this is the time to act, and there's plenty to act on. Let's focus on getting real work done. This is the D Summer of Code. :o) Andrei
Mar 30 2011
On 03/30/2011 10:30 PM, KennyTM~ wrote:On Mar 31, 11 11:24, Andrei Alexandrescu wrote:That makes sense, but I'd rather encourage our limited regular participants to use their limited time on constructive discussions that address needs both important and urgent. That would be a lot better than spreading ourselves too thin. AndreiOn 3/30/11 8:42 PM, Ary Manzana wrote:I think the GSoC group and language feature discussion group should be separated.I just hate it when you have to write too much to get simple things done. Does this type have a member? Current approach: 1. import std.traits; 2. invoke hasMember!(S, "m") Another approach: 1. I have the type, let's ask it: S::hasMember("m") Map's thought to code. My problem is that when you start using D's cool features you end up with a really hard to understand and obscure code...I understand and to a good extent agree with the sentiment. However, right now GSoC with student proposals to attract and review, an undergoing Phobos proposal review, one or a couple more waiting in the queue, good progress in core areas (64 bit stabilization, rigorous deterministic destruction, important bug fixes, and to follow the immutability subsystem and shared libraries) I can't stop feeling many of such discussions do more harm than good. There's always a better way to express a frequent idiom, and we may as well adopt one later. But this is the time to act, and there's plenty to act on. Let's focus on getting real work done. This is the D Summer of Code. :o) Andrei
Mar 30 2011
KennyTM~:I think the GSoC group and language feature discussion group should be separated.Regarding D/Phobos feature discussions, they don't damage the summer of code discussions significantly because they put in use almost a different part of the brain. The skills and attention required to write real code (or discuss closely about it, like discussion about what data structures to write down for the GSoC) are quite different from the skills needed to think about new design ideas for D or Phobos. For me such two things are so separated that I use one to relax my mind from doing the other too much. Said that, and given the limited number of people here, a further newsgroup split is not good. Bye, bearophile
Mar 31 2011
On 03/31/2011 03:52 AM, bearophile wrote:KennyTM~:They do share the same time budget. AndreiI think the GSoC group and language feature discussion group should be separated.Regarding D/Phobos feature discussions, they don't damage the summer of code discussions significantly because they put in use almost a different part of the brain.
Mar 31 2011
On Thu, 31 Mar 2011 10:16:58 -0400, Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> wrote:On 03/31/2011 03:52 AM, bearophile wrote:So don't read/respond to the posts. I think any discouragement for open discussion for any topic related to D is not a healthy attitude for an open community. If you want to have a GSOC-only discussion group, create a new newsgroup or mailing list. Do not hijack this group. -SteveKennyTM~:They do share the same time budget.I think the GSoC group and language feature discussion group should be separated.Regarding D/Phobos feature discussions, they don't damage the summer of code discussions significantly because they put in use almost a different part of the brain.
Mar 31 2011
On 03/31/2011 09:27 AM, Steven Schveighoffer wrote:On Thu, 31 Mar 2011 10:16:58 -0400, Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> wrote:Well you know it's considerably less simpler than that. Besides, I probably wasn't clear enough: I'm not discouraging anything as much as encouraging discussions that mark progress in important matters.On 03/31/2011 03:52 AM, bearophile wrote:So don't read/respond to the posts. I think any discouragement for open discussion for any topic related to D is not a healthy attitude for an open community.KennyTM~:They do share the same time budget.I think the GSoC group and language feature discussion group should be separated.Regarding D/Phobos feature discussions, they don't damage the summer of code discussions significantly because they put in use almost a different part of the brain.If you want to have a GSOC-only discussion group, create a new newsgroup or mailing list. Do not hijack this group.This is not about GSoC (it's but one of several items I mentioned), it's simply about making headway in topics that are important. Andrei
Mar 31 2011
On Thu, 31 Mar 2011 10:39:29 -0400, Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> wrote:On 03/31/2011 09:27 AM, Steven Schveighoffer wrote:That's a better statement. I just don't think such "unimportant" discussions are harmful or damaging, just don't participate if you don't want to be distracted. We're all (mostly) adults in charge of our own schedule. We don't need to be insulated from things.On Thu, 31 Mar 2011 10:16:58 -0400, Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> wrote:Well you know it's considerably less simpler than that. Besides, I probably wasn't clear enough: I'm not discouraging anything as much as encouraging discussions that mark progress in important matters.On 03/31/2011 03:52 AM, bearophile wrote:So don't read/respond to the posts. I think any discouragement for open discussion for any topic related to D is not a healthy attitude for an open community.KennyTM~:They do share the same time budget.I think the GSoC group and language feature discussion group should be separated.Regarding D/Phobos feature discussions, they don't damage the summer of code discussions significantly because they put in use almost a different part of the brain.Sorry if I got the wrong impression. I don't always read an entire thread when I see a post I want to respond to. -SteveIf you want to have a GSOC-only discussion group, create a new newsgroup or mailing list. Do not hijack this group.This is not about GSoC (it's but one of several items I mentioned), it's simply about making headway in topics that are important.
Mar 31 2011
On 31/03/2011 16:11, Steven Schveighoffer wrote:On Thu, 31 Mar 2011 10:39:29 -0400, Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> wrote:Yeah, kinda, but the thing is that such discussions are often done carrying the posture or tone that the language/compiler/library writers should work or address that issue soon (or even in the medium-term). That's perhaps what's most frustrating. -- Bruno Medeiros - Software EngineerOn 03/31/2011 09:27 AM, Steven Schveighoffer wrote:That's a better statement. I just don't think such "unimportant" discussions are harmful or damaging, just don't participate if you don't want to be distracted. We're all (mostly) adults in charge of our own schedule. We don't need to be insulated from things.On Thu, 31 Mar 2011 10:16:58 -0400, Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> wrote:Well you know it's considerably less simpler than that. Besides, I probably wasn't clear enough: I'm not discouraging anything as much as encouraging discussions that mark progress in important matters.On 03/31/2011 03:52 AM, bearophile wrote:So don't read/respond to the posts. I think any discouragement for open discussion for any topic related to D is not a healthy attitude for an open community.KennyTM~:They do share the same time budget.I think the GSoC group and language feature discussion group should be separated.Regarding D/Phobos feature discussions, they don't damage the summer of code discussions significantly because they put in use almost a different part of the brain.
Apr 07 2011
On 03/31/2011 05:24 AM, Andrei Alexandrescu wrote:Pleased to read that :-) I've had this sentiment for a while as well. I'm afraid this is frightening. Large pieces of Phobos are hard to read, imo (eg std.format). Denis -- _________________ vita es estrany spir.wikidot.comMy problem is that when you start using D's cool features you end up with a really hard to understand and obscure code...I understand and to a good extent agree with the sentiment.
Mar 31 2011
On 2011-03-31 01:05, KennyTM~ wrote:On Mar 31, 11 06:32, Ary Manzana wrote:In Ruby it would just be: S.hasMember("m") and "hasMember" would just be a regular plain old method, nothing special about it. -- /Jacob CarlborgOn 3/30/11 5:52 PM, KennyTM~ wrote:We're talking about __traits, a feature for compile-time reflection where most of its capability is already wrapped up to std.traits. It isn't comparable with the whole metaprogramming capability in another language. You know, metaprogramming is also heavily used in D, because of a sensible template system, mixins and CTFE, not __traits.On Mar 31, 11 04:19, Alix Pexton wrote:Look, metaprogramming in Ruby is a relatively advanced part of the language. And you know why it is heavily used and everyone can jump and start using it in a matter of seconds and build the most amazing things? Because it's very, very, very, (add 1000 very words here), very easy to use.On 30/03/2011 20:45, KennyTM~ wrote:That is almost like UFCS in D. int foo(string x, int y) { return x.length - y; } assert (foo("testing", 3) == 4); assert ("testing".foo(3) == 4); But OP's proposal is restricted to __traits only. __traits is a relatively advanced part of the language, plus many of its features has already been exposed via the library std.traits, e.g. std.traits.hasMember!(S, "m"), I don't think it really needs a very short syntax.This is confusing as :: is used to separate scopes in C++ (and PHP too).The first thing it reminded me of was Lua, where a single colon makes the left hand side into the first argument of the function on the right. foo:bar(x) ==> bar.(foo, x) So it felt kinda familiar to me ^^ A...Why make *anything* hard to use if you can do it in an easier way?Is meta.hasMember(S, "m") or even import std.traits; ... hasMember!(S, "m") really that hard to use? I think the 'meta' namespace is enough. 'A::B' is too much for such a low-level feature.
Mar 31 2011
On 2011-03-31 00:32, Ary Manzana wrote:On 3/30/11 5:52 PM, KennyTM~ wrote:Yes, because there is nothing special with how the meta information is accessed, just regular methods, no additional language support. -- /Jacob CarlborgOn Mar 31, 11 04:19, Alix Pexton wrote:Look, metaprogramming in Ruby is a relatively advanced part of the language. And you know why it is heavily used and everyone can jump and start using it in a matter of seconds and build the most amazing things? Because it's very, very, very, (add 1000 very words here), very easy to use. Why make *anything* hard to use if you can do it in an easier way?On 30/03/2011 20:45, KennyTM~ wrote:That is almost like UFCS in D. int foo(string x, int y) { return x.length - y; } assert (foo("testing", 3) == 4); assert ("testing".foo(3) == 4); But OP's proposal is restricted to __traits only. __traits is a relatively advanced part of the language, plus many of its features has already been exposed via the library std.traits, e.g. std.traits.hasMember!(S, "m"), I don't think it really needs a very short syntax.This is confusing as :: is used to separate scopes in C++ (and PHP too).The first thing it reminded me of was Lua, where a single colon makes the left hand side into the first argument of the function on the right. foo:bar(x) ==> bar.(foo, x) So it felt kinda familiar to me ^^ A...
Mar 31 2011
On 03/30/2011 09:45 PM, KennyTM~ wrote:On Mar 31, 11 03:28, Ary Manzana wrote:?I think :: is not used in the language. In a recent article about D I saw: mixin(__traits(identifier, T) ~ " " ~ to!string(tolower(__traits(identifier, T)[0])) ~ __traits(identifier, T)[1..$] ~ ";"); What if foo::bar were an alias for __traits(foo, bar) ? The code would look like this: mixin(T::identifier ~ " " ~ to!string(tolower(T::identifier[0])) ~ T::identifier[1..$] ~ ";"); What do you think? Another uses: __traits(int, isArithmetic) ==> int::isArithmetic __traits(C, isAbstractClass) ==> C::isAbstractClassYou've got the order wrong.D is not C++. D precisely exists to make things differently, ie its own way.__traits(hasMember, S, "m") ==> S::hasMember("m") Well, you get the idea... :: might be applied to other compile time uses, but I just came up with this...-1. This is confusing as :: is used to separate scopes in C++ (and PHP too). e.g.struct A { int x; bool isSame(const A other) pure const { return x == other.x; } } void main () { A a = A(2), b = A(2); assert ( a.isSame(b)); // ok assert (! a::isSame(b)); // ??? } (How about that 'meta' namespace proposal? meta.hasMember(S, "m") )This is no improvement about __traits. I'm all for a meta namespace, but it should be syntactically attractive. There is no contradiction between Ary's proposal meta, though the exact optimal syntax may not be that one. Denis -- _________________ vita es estrany spir.wikidot.com
Mar 30 2011
On 3/30/11 9:45 PM, KennyTM~ wrote:On Mar 31, 11 03:28, Ary Manzana wrote:I think think this is a valid reason. D does many things differently than C++. I don't know how many times I heard someone complaining about D's lack of struct inheritance. -- /Jacob CarlborgI think :: is not used in the language. In a recent article about D I saw: mixin(__traits(identifier, T) ~ " " ~ to!string(tolower(__traits(identifier, T)[0])) ~ __traits(identifier, T)[1..$] ~ ";"); What if foo::bar were an alias for __traits(foo, bar) ? The code would look like this: mixin(T::identifier ~ " " ~ to!string(tolower(T::identifier[0])) ~ T::identifier[1..$] ~ ";"); What do you think? Another uses: __traits(int, isArithmetic) ==> int::isArithmetic __traits(C, isAbstractClass) ==> C::isAbstractClassYou've got the order wrong.__traits(hasMember, S, "m") ==> S::hasMember("m") Well, you get the idea... :: might be applied to other compile time uses, but I just came up with this...-1. This is confusing as :: is used to separate scopes in C++ (and PHP too). e.g. struct A { int x; bool isSame(const A other) pure const { return x == other.x; } } void main () { A a = A(2), b = A(2); assert ( a.isSame(b)); // ok assert (! a::isSame(b)); // ??? } (How about that 'meta' namespace proposal? meta.hasMember(S, "m") )
Mar 31 2011
On 30/03/2011 20:28, Ary Manzana wrote:I think :: is not used in the language. In a recent article about D I saw: mixin(__traits(identifier, T) ~ " " ~ to!string(tolower(__traits(identifier, T)[0])) ~ __traits(identifier, T)[1..$] ~ ";"); What if foo::bar were an alias for __traits(foo, bar) ? The code would look like this: mixin(T::identifier ~ " " ~ to!string(tolower(T::identifier[0])) ~ T::identifier[1..$] ~ ";"); What do you think? Another uses: __traits(int, isArithmetic) ==> int::isArithmetic __traits(C, isAbstractClass) ==> C::isAbstractClass __traits(hasMember, S, "m") ==> S::hasMember("m") Well, you get the idea... :: might be applied to other compile time uses, but I just came up with this...Hmn, interesting idea! I noticed, however, that the "foo" and "bar" in your example are actually swapped... __traits(foo, bar) ==> foo::bar should be __traits(foo, bar) ==> bar::foo For many the uses of __traits I can recall off the top of my head, it certainly seems to be both elegant and intuitive. One sore thumb would be __traits(compiles, ...) which I believe gets used quite frequently in Phobos. Clarifications and my lack of insight into the complete breadth of __traits's capabilities and variations aside, I think this is the best suggestion for the replacement of the much maligned experimental keyword that I have seen posted since Don's suggestion of a magic namespace[1]. I'm not 100% sure if this :: syntax could also tidy up is() expressions too, but if it can, I can imagine it having a lot of support. If language design was a democracy, I'd certainly vote for it ^^ A... [1] Search the NG for "Proposal: Replace __traits and is(typeof(XXX)) with a 'magic namespace'."
Mar 30 2011
On 30/03/2011 21:09, Alix Pexton wrote:On 30/03/2011 20:28, Ary Manzana wrote:Damn I type slow ><I think :: is not used in the language. In a recent article about D I saw: mixin(__traits(identifier, T) ~ " " ~ to!string(tolower(__traits(identifier, T)[0])) ~ __traits(identifier, T)[1..$] ~ ";"); What if foo::bar were an alias for __traits(foo, bar) ? The code would look like this: mixin(T::identifier ~ " " ~ to!string(tolower(T::identifier[0])) ~ T::identifier[1..$] ~ ";"); What do you think? Another uses: __traits(int, isArithmetic) ==> int::isArithmetic __traits(C, isAbstractClass) ==> C::isAbstractClass __traits(hasMember, S, "m") ==> S::hasMember("m") Well, you get the idea... :: might be applied to other compile time uses, but I just came up with this...Hmn, interesting idea! I noticed, however, that the "foo" and "bar" in your example are actually swapped... __traits(foo, bar) ==> foo::bar should be __traits(foo, bar) ==> bar::foo For many the uses of __traits I can recall off the top of my head, it certainly seems to be both elegant and intuitive. One sore thumb would be __traits(compiles, ...) which I believe gets used quite frequently in Phobos. Clarifications and my lack of insight into the complete breadth of __traits's capabilities and variations aside, I think this is the best suggestion for the replacement of the much maligned experimental keyword that I have seen posted since Don's suggestion of a magic namespace[1]. I'm not 100% sure if this :: syntax could also tidy up is() expressions too, but if it can, I can imagine it having a lot of support. If language design was a democracy, I'd certainly vote for it ^^ A... [1] Search the NG for "Proposal: Replace __traits and is(typeof(XXX)) with a 'magic namespace'."
Mar 30 2011
On 03/30/2011 09:28 PM, Ary Manzana wrote:I think :: is not used in the language. In a recent article about D I saw: mixin(__traits(identifier, T) ~ " " ~ to!string(tolower(__traits(identifier, T)[0])) ~ __traits(identifier, T)[1..$] ~ ";"); What if foo::bar were an alias for __traits(foo, bar) ? The code would look like this: mixin(T::identifier ~ " " ~ to!string(tolower(T::identifier[0])) ~ T::identifier[1..$] ~ ";"); What do you think? Another uses: __traits(int, isArithmetic) ==> int::isArithmetic __traits(C, isAbstractClass) ==> C::isAbstractClass __traits(hasMember, S, "m") ==> S::hasMember("m") Well, you get the idea... :: might be applied to other compile time uses, but I just came up with this...Waow, this /is/ syntactic sugar ;-) Denis -- _________________ vita es estrany spir.wikidot.com
Mar 30 2011
On 3/30/11 9:28 PM, Ary Manzana wrote:I think :: is not used in the language. In a recent article about D I saw: mixin(__traits(identifier, T) ~ " " ~ to!string(tolower(__traits(identifier, T)[0])) ~ __traits(identifier, T)[1..$] ~ ";"); What if foo::bar were an alias for __traits(foo, bar) ? The code would look like this: mixin(T::identifier ~ " " ~ to!string(tolower(T::identifier[0])) ~ T::identifier[1..$] ~ ";"); What do you think? Another uses: __traits(int, isArithmetic) ==> int::isArithmetic __traits(C, isAbstractClass) ==> C::isAbstractClass __traits(hasMember, S, "m") ==> S::hasMember("m") Well, you get the idea... :: might be applied to other compile time uses, but I just came up with this...I like it. -- /Jacob Carlborg
Mar 31 2011
On Wed, 30 Mar 2011 22:28:27 +0300, Ary Manzana <ary esperanto.org.ar> wrote:I think :: is not used in the language. In a recent article about D I saw: mixin(__traits(identifier, T) ~ " " ~ to!string(tolower(__traits(identifier, T)[0])) ~ __traits(identifier, T)[1..$] ~ ";"); What if foo::bar were an alias for __traits(foo, bar) ? The code would look like this: mixin(T::identifier ~ " " ~ to!string(tolower(T::identifier[0])) ~ T::identifier[1..$] ~ ";"); What do you think? Another uses: __traits(int, isArithmetic) ==> int::isArithmetic __traits(C, isAbstractClass) ==> C::isAbstractClass __traits(hasMember, S, "m") ==> S::hasMember("m") Well, you get the idea... :: might be applied to other compile time uses, but I just came up with this...I agree it is a problem (a small one) but i don't believe it deserves a new syntax. Especially not a major one like this. Like many others i think "meta" is a much better choice.
Mar 31 2011
Ary Manzana Wrote:I just hate it when you have to write too muchhasMember!(S, "m") is only 1 character longer than S::hasMember("m") not too much for me
Mar 31 2011
On 3/31/11 10:35 AM, Kagamin wrote:Ary Manzana Wrote:Ah, so then I change it to: S::hm("M")I just hate it when you have to write too muchhasMember!(S, "m") is only 1 character longer than S::hasMember("m") not too much for me
Mar 31 2011
On 2011-03-31 06:35, Kagamin wrote:Ary Manzana Wrote:And hasMember!(S, "m") is actually consistent with the rest of the language and straight forward to read for those who know the language. S::hasMember("m") just adds more syntax where there's no need for it, and makes it so that there's that much more syntax to learn and keep straight. - Jonathan M DavisI just hate it when you have to write too muchhasMember!(S, "m") is only 1 character longer than S::hasMember("m") not too much for me
Mar 31 2011
On 31/03/2011 18:37, Jonathan M Davis wrote:On 2011-03-31 06:35, Kagamin wrote:I thought the :: syntax seemed pretty intuitive (keystroke savings never entered into my evaluation), but I seem to be in a minority on that. After re-reading the previous discussion of __traits and its proposed replacement, however, I am reminded of an important point: language features should not have special powers that can't be replicated in client code. So, with that in mind, I have to agree that using templates for things like hasMember has to be the way forward. Having templates that are internal to the complier or that simply forward to __traits seems a bit odd to me. I think I'd rather see __traits simplified and more of work moved into the library, which may make it more versatile and easier to extend (pure speculation ^^). Right, I'm off to go and squirrel all my uses or traits away inside templates, I have a sneaking suspicion that it is going to make some big improvements in readability ^^ A...Ary Manzana Wrote:And hasMember!(S, "m") is actually consistent with the rest of the language and straight forward to read for those who know the language. S::hasMember("m") just adds more syntax where there's no need for it, and makes it so that there's that much more syntax to learn and keep straight. - Jonathan M DavisI just hate it when you have to write too muchhasMember!(S, "m") is only 1 character longer than S::hasMember("m") not too much for me
Apr 01 2011
Alix Pexton wrote:On 31/03/2011 18:37, Jonathan M Davis wrote:The chief problem is that there is no way to hide __traits(compiles). It's just impossible. The whole idea of the meta namespace was to make it possible to hide the __traits. Don't forget that an important part of that proposal was to clean up is(), as well.On 2011-03-31 06:35, Kagamin wrote:I thought the :: syntax seemed pretty intuitive (keystroke savings never entered into my evaluation), but I seem to be in a minority on that. After re-reading the previous discussion of __traits and its proposed replacement, however, I am reminded of an important point: language features should not have special powers that can't be replicated in client code. So, with that in mind, I have to agree that using templates for things like hasMember has to be the way forward. Having templates that are internal to the complier or that simply forward to __traits seems a bit odd to me. I think I'd rather see __traits simplified and more of work moved into the library, which may make it more versatile and easier to extend (pure speculation ^^). Right, I'm off to go and squirrel all my uses or traits away inside templates, I have a sneaking suspicion that it is going to make some big improvements in readability ^^ A...Ary Manzana Wrote:And hasMember!(S, "m") is actually consistent with the rest of the language and straight forward to read for those who know the language. S::hasMember("m") just adds more syntax where there's no need for it, and makes it so that there's that much more syntax to learn and keep straight. - Jonathan M DavisI just hate it when you have to write too muchhasMember!(S, "m") is only 1 character longer than S::hasMember("m") not too much for me
Apr 01 2011