digitalmars.D - this() ctor() - don't read: wast ot time
- Ant (18/18) Jul 29 2004 Sorry, but...
- Jarrett Billingsley (2/2) Jul 29 2004 i don't know why, but it's not any worse than the class name, or ctor, o...
- Regan Heath (11/13) Jul 29 2004 I like 'this' it made sense as soon as I heard it. It's certainly better...
- Juanjo =?ISO-8859-15?Q?=C1lvarez?= (2/10) Jul 30 2004 init()
- me (20/21) Jul 30 2004 Wow, takes me back to my Turbo Pascal days ;-)
- Martin M. Pedersen (10/22) Jul 30 2004 I don't think it matters much if a keyword or the class name is used. It...
- teqDruid (8/35) Jul 30 2004 class Int
- Arcane Jill (9/32) Aug 01 2004 I should point out that the class Int does, in fact, have a constructor ...
- Bent Rasmussen (16/22) Jul 30 2004 A couple of alternatives
- me (5/8) Jul 30 2004 "Create", for example... and rather than using C++ legacy, 'Destroy' for...
- C. Sauls (11/14) Jul 30 2004 Hey don't worry Ant, secretly (guess its not secret anymore) I don't
- me (17/19) Jul 30 2004 What would be cool (should that route be followed) would be using ctor a...
- Phill (7/31) Jul 30 2004 I always thought that it was called this, because
- Elephant (2/20) Aug 02 2004
Sorry, but... I still don't understand why the ctor is called "this" instead of "constructor" or "ctor". nobody explained it to me... why not call trig1 instead of sin trig2 instead of cos trig3 instead of tan Poll: How long will Ant be able to hold before bringing up this thing again: ---------+>>>>> 6 hours | 1 day | 1 week | 1 month | 6 months | 1 year | X forever | Ant
Jul 29 2004
i don't know why, but it's not any worse than the class name, or ctor, or constructor. in fact this() kind of looks nice.
Jul 29 2004
On Fri, 30 Jul 2004 00:48:13 -0400, Jarrett Billingsley <kb3ctd2 yahoo.com> wrote:i don't know why, but it's not any worse than the class name, or ctor, or constructor. in fact this() kind of looks nice.I like 'this' it made sense as soon as I heard it. It's certainly better than typing the class name. 'constructor' is too long. 'ctor' only makes sense if you have heard that term used before. Can we overload 'new' for a class, if not 'new' for constructor and 'delete' for destructor would have worked. Regan. -- Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
Jul 29 2004
Regan Heath wrote:'constructor' is too long. 'ctor' only makes sense if you have heard that term used before. Can we overload 'new' for a class, if not 'new' for constructor and 'delete' for destructor would have worked. Regan.init()
Jul 30 2004
init()Wow, takes me back to my Turbo Pascal days ;-) var x1: Py; //heap x2: Ty; //stack begin x1 := new(Py, init); ... dispose(x1, done); x2.init; .... x2.done; end; "Done" never quite fitted for me. I still vote for Create and Destroy ('Free' as an alternate); also that using an extra operator to "delete" things is ver C++... X x = X.Create; .... x.Destroy; //or x.Free; Matt
Jul 30 2004
"Jarrett Billingsley" <kb3ctd2 yahoo.com> skrev i en meddelelse news:cecjt6$257o$1 digitaldaemon.com...i don't know why, but it's not any worse than the class name, or ctor, or constructor. in fact this() kind of looks nice.I don't think it matters much if a keyword or the class name is used. It do think, however, that it would add value to the language if the user was able to name the constructor, so one would be able to have different constructors taking the same arguments. Overloading on arguments isn't always enough. For example, you cannot have:class Int { this(char[] decDigits); this(char[] hexDigits); }However, this could work:class Int { ctor dec(char[] digits); ctor hex(char[] digits); }Regards, Martin M. Pedersen
Jul 30 2004
On Fri, 30 Jul 2004 19:52:00 +0200, Martin M. Pedersen wrote:"Jarrett Billingsley" <kb3ctd2 yahoo.com> skrev i en meddelelse news:cecjt6$257o$1 digitaldaemon.com...class Int { static Int ctorDec(char[] digits); static Int ctorHex(char[] digits); } Not as nice, but doable if necessary. Johni don't know why, but it's not any worse than the class name, or ctor, or constructor. in fact this() kind of looks nice.I don't think it matters much if a keyword or the class name is used. It do think, however, that it would add value to the language if the user was able to name the constructor, so one would be able to have different constructors taking the same arguments. Overloading on arguments isn't always enough. For example, you cannot have:class Int { this(char[] decDigits); this(char[] hexDigits); }However, this could work:class Int { ctor dec(char[] digits); ctor hex(char[] digits); }Regards, Martin M. Pedersen
Jul 30 2004
In article <pan.2004.07.30.18.28.59.941166 teqdruid.com>, teqDruid says...I should point out that the class Int does, in fact, have a constructor which takes only a char[]. (As well as a constructor which takes a char[] plus a radix). The char[]-only version parses the string. If it starts with "0x", it's hex. If it starts with "Ob", it's binary. And so on. If you don't want to to use such a prefix, you can use the (char[] digits, int radix) constructor. So, although this is an interesting idea, I don't think that the current system is necessarily deficient. Arcane Jillexample, you cannot have:class Int { static Int ctorDec(char[] digits); static Int ctorHex(char[] digits); }class Int { this(char[] decDigits); this(char[] hexDigits); }However, this could work:class Int { ctor dec(char[] digits); ctor hex(char[] digits); }Regards, Martin M. Pedersen
Aug 01 2004
However, this could work:A couple of alternatives class Int { static Int dec(char[] digits); static Int hex(char[] digits); } class Int // non-serious { enum Base {Dec, Hex} this(char[] digits, Base base); } Static functions aren't as clean though. In any event its probably a feature that constructor names don't depend on class names. As for using other names, its just a convention, many names will do, its just a matter of remembering what the name means, regardless of whether its "this", "ctor" or what have you.class Int { ctor dec(char[] digits); ctor hex(char[] digits); }
Jul 30 2004
"Ant" <duitoolkit yahoo.ca> wrote in message news:pan.2004.07.30.03.51.24.524418 yahoo.ca...Sorry, but... I still don't understand why the ctor is called "this" instead of "constructor" or "ctor"."Create", for example... and rather than using C++ legacy, 'Destroy' for the destructor, maybe? Matt
Jul 30 2004
Ant wrote:I still don't understand why the ctor is called "this" instead of "constructor" or "ctor". nobody explained it to me...Hey don't worry Ant, secretly (guess its not secret anymore) I don't like it either. I too would rather the name "ctor"... but my problem has more to do with the destructor. As far as I can tell, calling it "~this()" is little more than a C++ homage. In D, its a single special case of an identifier that's allowed to have a non-alpha-underscore beginning and has a special case meaning to the compiler/gc/language. Icky. I'd just assume have "ctor" and "dtor" but... I figure that bit has been set more or less in stone from the start. Oh well. -Chris S. -Invironz
Jul 30 2004
Icky. I'd just assume have "ctor" and "dtor" but... I figure that bit has been set more or less in stone from the start. Oh well.What would be cool (should that route be followed) would be using ctor and dtor as qualifiers/attributes: class X { ctor Create() { }; ctor CreateWithInt( int i ) { }; ctor CreateClone( X toClone ) { }; dtor Destroy() { }; } That would be cool. You then could have *named* constructors. That would make it worthwhile... That would make the language more verbose, but also more explicit. Matt
Jul 30 2004
Ant wrote:Sorry, but... I still don't understand why the ctor is called "this" instead of "constructor" or "ctor". nobody explained it to me... why not call trig1 instead of sin trig2 instead of cos trig3 instead of tan Poll: How long will Ant be able to hold before bringing up this thing again: ---------+>>>>> 6 hours | 1 day | 1 week | 1 month | 6 months | 1 year | X forever | AntI always thought that it was called this, because 'this' refers to the Object that was created when the thread entered the constructor. Each time the constructor is called a new 'this' is created which has its own copy of the variables and methods. Phill
Jul 30 2004
I personally like 'self'. In article <pan.2004.07.30.03.51.24.524418 yahoo.ca>, Ant says...Sorry, but... I still don't understand why the ctor is called "this" instead of "constructor" or "ctor". nobody explained it to me... why not call trig1 instead of sin trig2 instead of cos trig3 instead of tan Poll: How long will Ant be able to hold before bringing up this thing again: ---------+>>>>> 6 hours | 1 day | 1 week | 1 month | 6 months | 1 year | X forever | Ant
Aug 02 2004