www.digitalmars.com         C & C++   DMDScript  

D - Please don't remove :: and -> | static "this" member

reply "Brian Bober" <netdemonz yahoo.com> writes:
I don't agree with removing the :: and -> operators as they are part of
c++'s strong typing and can protect from coding errors.

Can we make it a rule that even constructors and destructors must be defined
properly, as in "void myClass(void)"?

I was also wondering if the "this" parameter of a function can be passed as
a static variable instead of on the stack? The reason for this
is so that initialized classes can be used as callback functions. Would
there be any problems with this?

For instance, in c++:

class myClass
{
    void myFunc(int a);
}

 void myFunc(int a); is really void myFunc(myClass * this, int a);

In D, can we have it:

class myClass
{
    void myFunc(int a);
    static myClass this;        //Hidden this
}

 void myFunc(int a); is really void myFunc(int a);
Feb 03 2002
parent reply "Pavel Minayev" <evilone omen.ru> writes:
"Brian Bober" <netdemonz yahoo.com> wrote in message
news:a3leoe$nv2$1 digitaldaemon.com...
 I don't agree with removing the :: and -> operators as they are part of
 c++'s strong typing and can protect from coding errors.
How? Trying to call a nonstatic method on class instead of object would give a compile-time error, so would a call to static method on object... I never understood the sence of having :: and ->. They are counter- exclusive, and can be replaced by the dot. They add nothing to type- safety, and they don't prevent ANY coding errors (if I'm wrong, give an example).
 Can we make it a rule that even constructors and destructors must be
defined
 properly, as in "void myClass(void)"?
WHY??? BTW there is no (void) in D. Use ().
 I was also wondering if the "this" parameter of a function can be passed
as
 a static variable instead of on the stack? The reason for this
 is so that initialized classes can be used as callback functions. Would
 there be any problems with this?

 For instance, in c++:

 class myClass
 {
     void myFunc(int a);
 }

  void myFunc(int a); is really void myFunc(myClass * this, int a);

 In D, can we have it:

 class myClass
 {
     void myFunc(int a);
     static myClass this;        //Hidden this
 }

  void myFunc(int a); is really void myFunc(int a);
What about reentrancy then?
Feb 04 2002
parent reply "OddesE" <OddesE_XYZ hotmail.com> writes:
"Pavel Minayev" <evilone omen.ru> wrote in message
news:a3lkkc$snf$1 digitaldaemon.com...
 "Brian Bober" <netdemonz yahoo.com> wrote in message
 news:a3leoe$nv2$1 digitaldaemon.com...
 I don't agree with removing the :: and -> operators as they are part of
 c++'s strong typing and can protect from coding errors.
How? Trying to call a nonstatic method on class instead of object would give a compile-time error, so would a call to static method on object... I never understood the sence of having :: and ->. They are counter- exclusive, and can be replaced by the dot. They add nothing to type- safety, and they don't prevent ANY coding errors (if I'm wrong, give an example).
 Can we make it a rule that even constructors and destructors must be
defined
 properly, as in "void myClass(void)"?
WHY??? BTW there is no (void) in D. Use ().
I guess Brian thinks it is more consistant... But it really doesn't make much sense. You have a special function, the constructor, which *never* returns a value, it is not allowed to, but you still make it mandatory that you define the return value as void... Furthermore, it is very welcome that there is a inconsistency (read difference) between regular functions and constructors and destructors, because the latter two are *not* regular functions and this will prevent them for being confused as one. I really like the fact that the names for constructors and destructors are changed from the class name to this and ~this. It really makes sense and you loose the dependancy of the name. If you change the name of a class, you don't lose the constructors. <SNIP> -- Stijn OddesE_XYZ hotmail.com http://OddesE.cjb.net __________________________________________ Remove _XYZ from my address when replying by mail
Feb 04 2002
parent reply "Walter" <walter digitalmars.com> writes:
"OddesE" <OddesE_XYZ hotmail.com> wrote in message
news:a3n6g4$21ia$1 digitaldaemon.com...
 I really like the fact that the names for constructors and destructors
 are changed from the class name to this and ~this. It really makes
 sense and you loose the dependancy of the name. If you change the
 name of a class, you don't lose the constructors.
Too many times I've had a bug where I'd mistyped the name of the class in the constructor, etc. Making it 'this' is a great idea. Makes them consistent, and they stand out. Also easier to parse <g>.
Feb 04 2002
parent reply "Roberto Mariottini" <rmariottini lycosmail.com> writes:
"Walter" <walter digitalmars.com> ha scritto nel messaggio
news:a3n7l0$24s5$1 digitaldaemon.com...
 "OddesE" <OddesE_XYZ hotmail.com> wrote in message
 news:a3n6g4$21ia$1 digitaldaemon.com...
 I really like the fact that the names for constructors and destructors
 are changed from the class name to this and ~this. It really makes
 sense and you loose the dependancy of the name. If you change the
 name of a class, you don't lose the constructors.
Too many times I've had a bug where I'd mistyped the name of the class in the constructor, etc. Making it 'this' is a great idea. Makes them consistent, and they stand out. Also easier to parse <g>.
Agreed. Consider also that the "~this" thing it's a little weird. I never liked to write "~ClassName", it's difficult to read (I often fail to find the destructor at a first look, or just think it's another constructor). Having to use a keyword to name contructors and destructors, why don't we use _other_ keywords? At least for destructors? Ciao P.S: I still don't have ~ on my keyboard ;-)
Feb 05 2002
next sibling parent reply "Walter" <walter digitalmars.com> writes:
"Roberto Mariottini" <rmariottini lycosmail.com> wrote in message
news:a3ok2t$2oan$1 digitaldaemon.com...
 P.S: I still don't have ~ on my keyboard ;-)
You can get a new keyboard for $10 <g>. Reminds me of many years ago at a programming conference where I, along with representatives from several compiler vendors, formed a panel taking questions from the audience. One question was "do you make a version for people with floppy only computers?" Vendor 1 says yes, we have a kludge version, blah, blah. Vendor 2 says yes, we have a crippled version for floppies, blah, blah. I say yes, we charge $200 extra for the floppy version and it comes with a hard disk drive. That was the last time that question ever came up (!). To put things in perspective, my new machine has an 80 gig drive about the size of a pack of cigarettes, for (you guessed it) $200.
Feb 05 2002
parent "Juan Carlos Arevalo Baeza" <jcab roningames.com> writes:
"Walter" <walter digitalmars.com> wrote in message
news:a3pirv$6vs$1 digitaldaemon.com...
 "Roberto Mariottini" <rmariottini lycosmail.com> wrote in message
 news:a3ok2t$2oan$1 digitaldaemon.com...
 P.S: I still don't have ~ on my keyboard ;-)
You can get a new keyboard for $10 <g>.
Maybe you're missing the point? Many international keyboards have missing characters, especially that one: ~. My Spanish keyboard is one of them. Of course, I've grown used to typing ALT+126. Either that or get an English keyboard.
 Reminds me of many years ago at a programming conference where I, along
with
 representatives from several compiler vendors, formed a panel taking
 questions from the audience. One question was "do you make a version for
 people with floppy only computers?" Vendor 1 says yes, we have a kludge
 version, blah, blah. Vendor 2 says yes, we have a crippled version for
 floppies, blah, blah. I say yes, we charge $200 extra for the floppy
version
 and it comes with a hard disk drive.
<sarcasm> So let's offer a new english-layout keyboard with the compiler... </sarcasm> It's not a matter of money, Walter. From his name, I'm guessing his problem is that he has an italian keyboard. ;-) Salutaciones, JCAB
Feb 05 2002
prev sibling parent reply "Juan Carlos Arevalo Baeza" <jcab roningames.com> writes:
"Roberto Mariottini" <rmariottini lycosmail.com> wrote in message
news:a3ok2t$2oan$1 digitaldaemon.com...
 Consider also that the "~this" thing it's a little weird. I never liked to
 write "~ClassName", it's difficult to read (I often fail to find the
 destructor
 at a first look, or just think it's another constructor).
 Having to use a keyword to name contructors and destructors, why
 don't we use _other_ keywords? At least for destructors?
I always wondered what's wrong with using proper names, like constructor() and destructor(). It's clear and to the point. In C++, I understand (although I disagree with) their need to keep new keywords to a minimum. D has no such problem. Salutaciones, JCAB
Feb 05 2002
next sibling parent reply "OddesE" <OddesE_XYZ hotmail.com> writes:
"Juan Carlos Arevalo Baeza" <jcab roningames.com> wrote in message
news:a3pleu$jvi$1 digitaldaemon.com...
 "Roberto Mariottini" <rmariottini lycosmail.com> wrote in message
 news:a3ok2t$2oan$1 digitaldaemon.com...
 Consider also that the "~this" thing it's a little weird. I never liked
to
 write "~ClassName", it's difficult to read (I often fail to find the
 destructor
 at a first look, or just think it's another constructor).
 Having to use a keyword to name contructors and destructors, why
 don't we use _other_ keywords? At least for destructors?
I always wondered what's wrong with using proper names, like constructor() and destructor(). It's clear and to the point. In C++, I understand (although I disagree with) their need to keep new keywords to a minimum. D has no such problem. Salutaciones, JCAB
A good point. I like this() and ~this better than the old C++ style, but I like this even better. It is just so more easy to read! -- Stijn OddesE_XYZ hotmail.com http://OddesE.cjb.net __________________________________________ Remove _XYZ from my address when replying by mail
Feb 05 2002
parent "Pavel Minayev" <evilone omen.ru> writes:
I must say that I'm pretty happy with current syntax.
It's short and to point =) But this is the matter of
personal taste, indeed.
Feb 05 2002
prev sibling parent reply "Robert W. Cunningham" <rwc_2001 yahoo.com> writes:
Juan Carlos Arevalo Baeza wrote:

 "Roberto Mariottini" <rmariottini lycosmail.com> wrote in message
 news:a3ok2t$2oan$1 digitaldaemon.com...
 Consider also that the "~this" thing it's a little weird. I never liked to
 write "~ClassName", it's difficult to read (I often fail to find the
 destructor
 at a first look, or just think it's another constructor).
 Having to use a keyword to name contructors and destructors, why
 don't we use _other_ keywords? At least for destructors?
I always wondered what's wrong with using proper names, like constructor() and destructor(). It's clear and to the point. In C++, I understand (although I disagree with) their need to keep new keywords to a minimum. D has no such problem. Salutaciones, JCAB
Personally, I'd prefer "ctor" and "dtor": Fewer characters, and it is already a common notation in tools and CS literature. Don't get me wrong: "this" and "~this" are fine with me, as is "super". They fit together nicely. But the notion of "this", as it is used in all the CS OO literature (an instance pointer or handle), is quite different from what D means by "this" (a function). Since I don't want to type more characters, "ctor" and "dtor" are simply nice, concise drop-in replacements. I do, however, have a minor hang-up with the use of "~", which generally means "not" in most CS usage. So, to me, "~this" means "not this", which can only mean "that". So, logically, D should use "this" as the constructor name, and "that" as the destructor name. ;^) And get rid of the tilde, which will have the beneficial effect of ending the use of Alt+126 forever! (Well, at least for D programmers.) [Why is it that so many people without a tilde on their keyboards have four names? If I scratch the tilde off my backquote key, can I have four names too?] The fundamental gain is to NOT propagate C++'s error of reusing the class name as member function names! This changes (overloads) the notion of the a name within its own context! Ugh! It's a one line sed/awk/perl/whatever script to make the ctor/dtor change in all existing D code (on any given system, that is). It's not too late... -BobC
Feb 05 2002
parent "Juan Carlos Arevalo Baeza" <jcab roningames.com> writes:
"Robert W. Cunningham" <rwc_2001 yahoo.com> wrote in message
news:3C60B0F8.DF48C5F7 yahoo.com...
 Personally, I'd prefer "ctor" and "dtor":  Fewer characters, and it is
already
 a common notation in tools and CS literature.
I prefer a little bit of verbosity, for clarity's sake. Not very religious about it, though.
 I do, however, have a minor hang-up with the use of "~", which generally
means
 "not" in most CS usage.  So, to me, "~this" means "not this", which can
only
 mean "that".  So, logically, D should use "this" as the constructor name,
and
 "that" as the destructor name.  ;^)
:) That's funny.
 And get rid of the tilde, which will have
 the beneficial effect of ending the use of Alt+126 forever!  (Well, at
least
 for D programmers.)  [Why is it that so many people without a tilde on
their
 keyboards have four names?  If I scratch the tilde off my backquote key,
can
 I have four names too?]
He he... I have my own explanation: http://www.jcabs-rumblings.com/JAQ.html#whylongname
 The fundamental gain is to NOT propagate C++'s error of reusing the class
name
 as member function names!  This changes (overloads) the notion of the a
name
 within its own context!  Ugh!
There was a reason for that: multiple inheritance. But that's not an issue in D. Salutaciones, JCAB
Feb 06 2002