digitalmars.D - defered new feature
- BCS (7/28) Oct 23 2008 A number of times I have found my self wanting to have "new C(args)" ret...
- Andrei Alexandrescu (3/6) Oct 23 2008 I'd say the stupid "new" is unappealing.
- BCS (4/14) Oct 23 2008 So you don't like "new" all together?
- Andrei Alexandrescu (5/21) Oct 23 2008 I consider it an unnecessary appendage and a waste of two keywords
- BCS (5/32) Oct 23 2008 You can't dump delete (unless you propose having a delete property) beca...
- Andrei Alexandrescu (3/28) Oct 23 2008 It's a function!!!
- downs (6/9) Oct 23 2008 Amusing fact: you can assign to "this" in the constructor.
- BCS (3/6) Oct 23 2008 to bad it doesn't compile :(
- downs (12/23) Oct 24 2008 gentoo-pc ~ $ cat test113.d && echo "----" && gdc test113.d -o test113 &...
- BCS (3/19) Oct 24 2008 Oops.
- Jarrett Billingsley (6/15) Oct 23 2008 I once used this looong ago when I first came to D so that attempting
A number of times I have found my self wanting to have "new C(args)" return a class derived from C. I know this can be done with a static function or the like but syntactically, it's unappealing. My suggestion is that, with some kind of flag, constructors be allowed and required to construct an object and return it. One use cases:class C { abstract void F(); /// abstract class abstract this(int i) /// "abstract" this is just one idea, others wouldwork as well{ if(i < 0) return new N(-i); else return new P(i); } } private class N : C { void F(); this(uint i){} } private class P : C { void F(); this(uint i){} }
Oct 23 2008
BCS wrote:A number of times I have found my self wanting to have "new C(args)" return a class derived from C. I know this can be done with a static function or the like but syntactically, it's unappealing.I'd say the stupid "new" is unappealing. Andrei
Oct 23 2008
Reply to Andrei,BCS wrote:So you don't like "new" all together? Ok, then morph the idea to allow "the constructor call syntax" to do the above.A number of times I have found my self wanting to have "new C(args)" return a class derived from C. I know this can be done with a static function or the like but syntactically, it's unappealing.I'd say the stupid "new" is unappealing. Andrei
Oct 23 2008
BCS wrote:Reply to Andrei,I consider it an unnecessary appendage and a waste of two keywords (considering delete too).BCS wrote:So you don't like "new" all together?A number of times I have found my self wanting to have "new C(args)" return a class derived from C. I know this can be done with a static function or the like but syntactically, it's unappealing.I'd say the stupid "new" is unappealing. AndreiOk, then morph the idea to allow "the constructor call syntax" to do the above.Then we're pretty much down to functions :o). Andrei
Oct 23 2008
Reply to Andrei,BCS wrote:You can't dump delete (unless you propose having a delete property) because D still allows manual memory management.Reply to Andrei,I consider it an unnecessary appendage and a waste of two keywords (considering delete too).BCS wrote:So you don't like "new" all together?A number of times I have found my self wanting to have "new C(args)" return a class derived from C. I know this can be done with a static function or the like but syntactically, it's unappealing.I'd say the stupid "new" is unappealing. AndreiYes they might look the same, but /some/ magic will be needed to make overloading work because constructors already have some magic in them.Ok, then morph the idea to allow "the constructor call syntax" to do the above.Then we're pretty much down to functions :o).Andrei
Oct 23 2008
BCS wrote:Reply to Andrei,It's a function!!! AndreiBCS wrote:You can't dump delete (unless you propose having a delete property) because D still allows manual memory management.Reply to Andrei,I consider it an unnecessary appendage and a waste of two keywords (considering delete too).BCS wrote:So you don't like "new" all together?A number of times I have found my self wanting to have "new C(args)" return a class derived from C. I know this can be done with a static function or the like but syntactically, it's unappealing.I'd say the stupid "new" is unappealing. Andrei
Oct 23 2008
BCS wrote:A number of times I have found my self wanting to have "new C(args)" return a class derived from C. I know this can be done with a static function or the like but syntactically, it's unappealing.Amusing fact: you can assign to "this" in the constructor. typedef bool Bogus; const Bogus bogus = false; class A { this() { this = new B; } this(Bogus) { } } class B : A { this() { super(bogus); /* rest of constructor */ } }
Oct 23 2008
Reply to Downs,class A { this() { this = new B; } this(Bogus) { } } class B : A { this() { super(bogus); /* rest of constructor */ } }to bad it doesn't compile :( http://codepad.org/xkBAzQ2c -> SEG-V (if you drop the /* */)
Oct 23 2008
BCS wrote:Reply to Downs,gentoo-pc ~ $ cat test113.d && echo "----" && gdc test113.d -o test113 && ./test113 module test113; typedef bool Bogus; const Bogus bogus = false; class A { this() { this = new B; } this(Bogus) { } } class B : A { this() { super(bogus); /* rest of constructor */ } } import std.stdio; void main() { writefln(new A); } ---- test113.B gentoo-pc ~ $class A { this() { this = new B; } this(Bogus) { } } class B : A { this() { super(bogus); /* rest of constructor */ } }to bad it doesn't compile :( http://codepad.org/xkBAzQ2c -> SEG-V (if you drop the /* */)
Oct 24 2008
Reply to Downs,BCS wrote:Oops. http://codepad.org/CYTJzhJcto bad it doesn't compile :(gentoo-pc ~ $ cat test113.d && echo "----" && gdc test113.d -o test113 && ./test113 module test113; typedef bool Bogus; const Bogus bogus = false; class A { this() { this = new B; } this(Bogus) { } } class B : A { this() { super(bogus); /* rest of constructor */ } } import std.stdio; void main() { writefln(new A); } ---- test113.B gentoo-pc ~ $
Oct 24 2008
On Thu, Oct 23, 2008 at 9:31 PM, downs <default_357-line yahoo.de> wrote:BCS wrote:I once used this looong ago when I first came to D so that attempting to do a "new Texture(`some/file`)" twice on the same file would return the same texture object. Of course, at the time, it didn't occur to me that (1) that was horribly hackish or (2) that a static method would have been much better there XDA number of times I have found my self wanting to have "new C(args)" return a class derived from C. I know this can be done with a static function or the like but syntactically, it's unappealing.Amusing fact: you can assign to "this" in the constructor. typedef bool Bogus; const Bogus bogus = false; class A { this() { this = new B; } this(Bogus) { } } class B : A { this() { super(bogus); /* rest of constructor */ } }
Oct 23 2008