www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Get constructor for a class

reply "simendsjo" <simendsjo gmail.com> writes:
allMembers returns "this", but trying to get "this" or "__ctor" 
using getMember fails. Is there any way to get this method?
Sep 13 2013
parent reply "Gary Willoughby" <dev nomad.so> writes:
On Friday, 13 September 2013 at 09:12:53 UTC, simendsjo wrote:
 allMembers returns "this", but trying to get "this" or "__ctor" 
 using getMember fails. Is there any way to get this method?
foreach (func; __traits(getOverloads, T, "__ctor")) { ... }
Sep 13 2013
parent reply "simendsjo" <simendsjo gmail.com> writes:
On Friday, 13 September 2013 at 13:16:12 UTC, Gary Willoughby 
wrote:
 On Friday, 13 September 2013 at 09:12:53 UTC, simendsjo wrote:
 allMembers returns "this", but trying to get "this" or 
 "__ctor" using getMember fails. Is there any way to get this 
 method?
foreach (func; __traits(getOverloads, T, "__ctor")) { ... }
Thanks. Still a bit strange though.. "this" is always a member for classes, but if there's only an implicit ctor, only "this" exists, and getOverloads "__ctor" fails. If there exists explicit ctors on the other hand, both "this" *and* "__ctor" exists.
Sep 13 2013
parent reply "Gary Willoughby" <dev nomad.so> writes:
On Friday, 13 September 2013 at 13:31:34 UTC, simendsjo wrote:
 On Friday, 13 September 2013 at 13:16:12 UTC, Gary Willoughby 
 wrote:
 On Friday, 13 September 2013 at 09:12:53 UTC, simendsjo wrote:
 allMembers returns "this", but trying to get "this" or 
 "__ctor" using getMember fails. Is there any way to get this 
 method?
foreach (func; __traits(getOverloads, T, "__ctor")) { ... }
Thanks. Still a bit strange though.. "this" is always a member for classes, but if there's only an implicit ctor, only "this" exists, and getOverloads "__ctor" fails. If there exists explicit ctors on the other hand, both "this" *and* "__ctor" exists.
A lot of the traits stuff is very confusing, i think a lot of it is still being finalised and in development. I'm working on a project using a lot of traits stuff and it's doing my head in. I wish there was better documentation. e.g. what is 'func' in the code above? i'm using it successfully but i've no idea what it is.
Sep 13 2013
parent reply "simendsjo" <simendsjo gmail.com> writes:
On Friday, 13 September 2013 at 14:02:15 UTC, Gary Willoughby 
wrote:
 On Friday, 13 September 2013 at 13:31:34 UTC, simendsjo wrote:
 On Friday, 13 September 2013 at 13:16:12 UTC, Gary Willoughby 
 wrote:
 On Friday, 13 September 2013 at 09:12:53 UTC, simendsjo wrote:
 allMembers returns "this", but trying to get "this" or 
 "__ctor" using getMember fails. Is there any way to get this 
 method?
foreach (func; __traits(getOverloads, T, "__ctor")) { ... }
Thanks. Still a bit strange though.. "this" is always a member for classes, but if there's only an implicit ctor, only "this" exists, and getOverloads "__ctor" fails. If there exists explicit ctors on the other hand, both "this" *and* "__ctor" exists.
A lot of the traits stuff is very confusing, i think a lot of it is still being finalised and in development. I'm working on a project using a lot of traits stuff and it's doing my head in. I wish there was better documentation. e.g. what is 'func' in the code above? i'm using it successfully but i've no idea what it is.
I know what you mean. Have been using quite some __traits and is(), and I still have to look up the syntax for is() all the time, and experiment with both trying to find the edge-cases. My biggest problem is that there's only one possible context pointer for templates and that often DMD is unable to use contexts even though they are mixed in at the call-site and really should be available...
Sep 13 2013
parent reply "H. S. Teoh" <hsteoh quickfur.ath.cx> writes:
On Fri, Sep 13, 2013 at 04:16:30PM +0200, simendsjo wrote:
 On Friday, 13 September 2013 at 14:02:15 UTC, Gary Willoughby wrote:
[...]
A lot of the traits stuff is very confusing, i think a lot of it
is still being finalised and in development. I'm working on a
project using a lot of traits stuff and it's doing my head in. I
wish there was better documentation. e.g. what is 'func' in the
code above? i'm using it successfully but i've no idea what it is.
I know what you mean. Have been using quite some __traits and is(), and I still have to look up the syntax for is() all the time, and experiment with both trying to find the edge-cases.
[...] The syntax for is() is one gigantic mess. It does work, but it's not pretty. IIRC Walter admitted that it could do with some cleanup, but it's a bit too late now since too much code relies on its quirks. As for __traits, I believe the intention was that it wasn't meant for end-user consumption, but for Phobos to be able to access compiler internals. As such, it only provides the bare minimum for Phobos to be able to work, so there are a lot of quirks and edge cases. I was quite dismayed yesterday to discover that "parameter type tuples" are actually different from the usual "type tuples", and don't even behave consistently with foreach (they masquerade as type tuples w.r.t. foreach, and there's weird special-casing for 1-element slices of them, e.g. for __traits(identifier...)). I don't know what's the rationale for this strange design, but it sure looks like it was just a quick hack to make Phobos work rather than anything carefully thought out. Personally, I would just stick with the Phobos interfaces, and file bugs (or pull requests) if the existing interfaces aren't sufficient for your needs. T -- Let X be the set not defined by this sentence...
Sep 13 2013
parent reply "Namespace" <rswhite4 googlemail.com> writes:
On Friday, 13 September 2013 at 15:16:36 UTC, H. S. Teoh wrote:
 On Fri, Sep 13, 2013 at 04:16:30PM +0200, simendsjo wrote:
 On Friday, 13 September 2013 at 14:02:15 UTC, Gary Willoughby 
 wrote:
[...]
A lot of the traits stuff is very confusing, i think a lot of 
it
is still being finalised and in development. I'm working on a
project using a lot of traits stuff and it's doing my head 
in. I
wish there was better documentation. e.g. what is 'func' in 
the
code above? i'm using it successfully but i've no idea what 
it is.
I know what you mean. Have been using quite some __traits and is(), and I still have to look up the syntax for is() all the time, and experiment with both trying to find the edge-cases.
[...] The syntax for is() is one gigantic mess. It does work, but it's not pretty. IIRC Walter admitted that it could do with some cleanup, but it's a bit too late now since too much code relies on its quirks. As for __traits, I believe the intention was that it wasn't meant for end-user consumption, but for Phobos to be able to access compiler internals. As such, it only provides the bare minimum for Phobos to be able to work, so there are a lot of quirks and edge cases. I was quite dismayed yesterday to discover that "parameter type tuples" are actually different from the usual "type tuples", and don't even behave consistently with foreach (they masquerade as type tuples w.r.t. foreach, and there's weird special-casing for 1-element slices of them, e.g. for __traits(identifier...)). I don't know what's the rationale for this strange design, but it sure looks like it was just a quick hack to make Phobos work rather than anything carefully thought out. Personally, I would just stick with the Phobos interfaces, and file bugs (or pull requests) if the existing interfaces aren't sufficient for your needs. T
We should clean up this mess in 'is' and 'traits' and especially for tuples. IMO it's ok if it breaks code as long as it helps to write cleaner and tough code. This will also help D to gain more attention. There is so many crap in D... We should really start to clean up as long as D2 is still a Beta. And we should stop to transform it into something like C++ with transferring built-in features into the library (like scope or delete).
Sep 13 2013
parent reply "simendsjo" <simendsjo gmail.com> writes:
On Friday, 13 September 2013 at 15:27:42 UTC, Namespace wrote:
 On Friday, 13 September 2013 at 15:16:36 UTC, H. S. Teoh wrote:
 On Fri, Sep 13, 2013 at 04:16:30PM +0200, simendsjo wrote:
 On Friday, 13 September 2013 at 14:02:15 UTC, Gary Willoughby 
 wrote:
[...]
(...)
 The syntax for is() is one gigantic mess. It does work, but 
 it's not
 pretty. IIRC Walter admitted that it could do with some 
 cleanup, but
 it's a bit too late now since too much code relies on its 
 quirks.
(...)
 We should clean up this mess in 'is' and 'traits' and 
 especially for tuples. IMO it's ok if it breaks code as long as 
 it helps to write cleaner and tough code. This will also help D 
 to gain more attention.
 There is so many crap in D... We should really start to clean 
 up as long as D2 is still a Beta.
 And we should stop to transform it into something like C++ with 
 transferring built-in features into the library (like scope or 
 delete).
D2 is in beta...? I agree is() and __traits is quite messy, and I have quite some workarounds for various stuff in the combination of is() __traits(), alias, enum and templates - basically generic programming. But I doubt many people here agree D2 is in beta and will allow breaking existing code in ways that changing the aforementioned features would do.
Sep 13 2013
next sibling parent "Namespace" <rswhite4 googlemail.com> writes:
On Friday, 13 September 2013 at 22:10:02 UTC, simendsjo wrote:
 On Friday, 13 September 2013 at 15:27:42 UTC, Namespace wrote:
 On Friday, 13 September 2013 at 15:16:36 UTC, H. S. Teoh wrote:
 On Fri, Sep 13, 2013 at 04:16:30PM +0200, simendsjo wrote:
 On Friday, 13 September 2013 at 14:02:15 UTC, Gary 
 Willoughby wrote:
[...]
(...)
 The syntax for is() is one gigantic mess. It does work, but 
 it's not
 pretty. IIRC Walter admitted that it could do with some 
 cleanup, but
 it's a bit too late now since too much code relies on its 
 quirks.
(...)
 We should clean up this mess in 'is' and 'traits' and 
 especially for tuples. IMO it's ok if it breaks code as long 
 as it helps to write cleaner and tough code. This will also 
 help D to gain more attention.
 There is so many crap in D... We should really start to clean 
 up as long as D2 is still a Beta.
 And we should stop to transform it into something like C++ 
 with transferring built-in features into the library (like 
 scope or delete).
D2 is in beta...? I agree is() and __traits is quite messy, and I have quite some workarounds for various stuff in the combination of is() __traits(), alias, enum and templates - basically generic programming. But I doubt many people here agree D2 is in beta and will allow breaking existing code in ways that changing the aforementioned features would do.
Not...? It's far away from final. o.O If D2 is final I tend to leave this scene... It more broken than C++ ever was.
Sep 13 2013
prev sibling parent reply Jacob Carlborg <doob me.com> writes:
On 2013-09-14 00:10, simendsjo wrote:

 But I doubt many people here agree D2 is in beta and will allow breaking
 existing code in ways that changing the aforementioned features would do.
DMD breaks code in every single release. All 2.05x and 2.06x releases have caused code breakage for DWT in some way or another. -- /Jacob Carlborg
Sep 14 2013
parent reply "simendsjo" <simendsjo gmail.com> writes:
On Saturday, 14 September 2013 at 11:00:26 UTC, Jacob Carlborg 
wrote:
 On 2013-09-14 00:10, simendsjo wrote:

 But I doubt many people here agree D2 is in beta and will 
 allow breaking
 existing code in ways that changing the aforementioned 
 features would do.
DMD breaks code in every single release. All 2.05x and 2.06x releases have caused code breakage for DWT in some way or another.
I know each release breaks code in various ways, but if 2.064 was to redesign is() and __traits() without maintaining backwards compability I think many people would fork/leave D altogether. So I'm not sure if I would call it beta even if each release breaks code due to bugs, bugfixes, removing code that shouldn't be allowed i the first place etc.
Sep 14 2013
parent reply "Namespace" <rswhite4 googlemail.com> writes:
On Saturday, 14 September 2013 at 11:29:33 UTC, simendsjo wrote:
 On Saturday, 14 September 2013 at 11:00:26 UTC, Jacob Carlborg 
 wrote:
 On 2013-09-14 00:10, simendsjo wrote:

 But I doubt many people here agree D2 is in beta and will 
 allow breaking
 existing code in ways that changing the aforementioned 
 features would do.
DMD breaks code in every single release. All 2.05x and 2.06x releases have caused code breakage for DWT in some way or another.
I know each release breaks code in various ways, but if 2.064 was to redesign is() and __traits() without maintaining backwards compability I think many people would fork/leave D altogether. So I'm not sure if I would call it beta even if each release breaks code due to bugs, bugfixes, removing code that shouldn't be allowed i the first place etc.
Then tell me, what do you call it then? final? ;)
Sep 14 2013
parent reply "simendsjo" <simendsjo gmail.com> writes:
On Saturday, 14 September 2013 at 11:45:38 UTC, Namespace wrote:
 On Saturday, 14 September 2013 at 11:29:33 UTC, simendsjo wrote:
 On Saturday, 14 September 2013 at 11:00:26 UTC, Jacob Carlborg 
 wrote:
 On 2013-09-14 00:10, simendsjo wrote:

 But I doubt many people here agree D2 is in beta and will 
 allow breaking
 existing code in ways that changing the aforementioned 
 features would do.
DMD breaks code in every single release. All 2.05x and 2.06x releases have caused code breakage for DWT in some way or another.
I know each release breaks code in various ways, but if 2.064 was to redesign is() and __traits() without maintaining backwards compability I think many people would fork/leave D altogether. So I'm not sure if I would call it beta even if each release breaks code due to bugs, bugfixes, removing code that shouldn't be allowed i the first place etc.
Then tell me, what do you call it then? final? ;)
I've been waiting it to be final since 2007 :) Getting better by leaps and bounds though.
Sep 14 2013
parent "Namespace" <rswhite4 googlemail.com> writes:
On Saturday, 14 September 2013 at 13:14:50 UTC, simendsjo wrote:
 On Saturday, 14 September 2013 at 11:45:38 UTC, Namespace wrote:
 On Saturday, 14 September 2013 at 11:29:33 UTC, simendsjo 
 wrote:
 On Saturday, 14 September 2013 at 11:00:26 UTC, Jacob 
 Carlborg wrote:
 On 2013-09-14 00:10, simendsjo wrote:

 But I doubt many people here agree D2 is in beta and will 
 allow breaking
 existing code in ways that changing the aforementioned 
 features would do.
DMD breaks code in every single release. All 2.05x and 2.06x releases have caused code breakage for DWT in some way or another.
I know each release breaks code in various ways, but if 2.064 was to redesign is() and __traits() without maintaining backwards compability I think many people would fork/leave D altogether. So I'm not sure if I would call it beta even if each release breaks code due to bugs, bugfixes, removing code that shouldn't be allowed i the first place etc.
Then tell me, what do you call it then? final? ;)
I've been waiting it to be final since 2007 :) Getting better by leaps and bounds though.
But still a long long way. :)
Sep 14 2013