www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - this() ctor() - don't read: wast ot time

reply Ant <duitoolkit yahoo.ca> writes:
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
next sibling parent reply "Jarrett Billingsley" <kb3ctd2 yahoo.com> writes:
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
next sibling parent reply Regan Heath <regan netwin.co.nz> writes:
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
parent reply Juanjo =?ISO-8859-15?Q?=C1lvarez?= <juanjuxNO SPAMyahoo.es> writes:
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
parent "me" <memsom interalpha.co.uk> writes:
 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
prev sibling parent reply "Martin M. Pedersen" <martin moeller-pedersen.dk> writes:
"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
next sibling parent reply teqDruid <me teqdruid.com> writes:
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
Jul 30 2004
parent Arcane Jill <Arcane_member pathlink.com> writes:
In article <pan.2004.07.30.18.28.59.941166 teqdruid.com>, teqDruid says...
 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); }
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 Jill
Aug 01 2004
prev sibling parent "Bent Rasmussen" <exo bent-rasmussen.info> writes:
 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.
Jul 30 2004
prev sibling next sibling parent "me" <memsom interalpha.co.uk> writes:
"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
prev sibling next sibling parent reply "C. Sauls" <ibisbasenji yahoo.com> writes:
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
parent "me" <memsom interalpha.co.uk> writes:
 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
prev sibling next sibling parent Phill <phill pacific.net.au> writes:
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	 |
 
 Ant
 
I 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
prev sibling parent Elephant <Elephant_member pathlink.com> writes:
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