Thread overview | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
July 30, 2004 this() ctor() - don't read: wast ot time | ||||
---|---|---|---|---|
| ||||
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 |
July 30, 2004 Re: this() ctor() - don't read: wast ot time | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ant | 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. |
July 30, 2004 Re: this() ctor() - don't read: wast ot time | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jarrett Billingsley | 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/ |
July 30, 2004 Re: this() ctor() - don't read: wast ot time | ||||
---|---|---|---|---|
| ||||
Posted in reply to Regan Heath | 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()
|
July 30, 2004 Re: this() ctor() - don't read: wast ot time | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ant | "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 |
July 30, 2004 Re: this() ctor() - don't read: wast ot time | ||||
---|---|---|---|---|
| ||||
Posted in reply to Juanjo Álvarez | > 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
|
July 30, 2004 Re: this() ctor() - don't read: wast ot time | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jarrett Billingsley | "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 |
July 30, 2004 Re: this() ctor() - don't read: wast ot time | ||||
---|---|---|---|---|
| ||||
Posted in reply to Martin M. Pedersen | 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...
>> 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
class Int
{
static Int ctorDec(char[] digits);
static Int ctorHex(char[] digits);
}
Not as nice, but doable if necessary.
John
|
July 30, 2004 Re: this() ctor() - don't read: wast ot time | ||||
---|---|---|---|---|
| ||||
Posted in reply to Martin M. Pedersen | > However, this could work:
>
> > class Int
> > {
> > ctor dec(char[] digits);
> > ctor hex(char[] digits);
> > }
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.
|
July 30, 2004 Re: this() ctor() - don't read: wast ot time | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ant | 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
|
Copyright © 1999-2021 by the D Language Foundation