Please stop polluting D 2.0 with C/C++ programmer assumptions.

Walter Bright newshound1 at digitalmars.com
Thu Nov 29 12:34:01 PST 2007


Tomas Lindquist Olsen wrote:
> I've been trying to follow the NG lately (which is fairly time 
> consuming) and I really only have one thing to say:
> 
> 1) Remove the support for C style declaration.
> 2) Make suffix const the only way to declare a const method.
> 3) Stop assuming C++ programmers wants D to feel like C++.
> 4) Please...
> 
> This stuff is killing me! For the first time in D2.0 history I'm feeling 
> it's on the right track, but things like:
> 
> class C {
>     const const int[] func();
> }
> 
> class ClassInfo {
>     void (*classInvariant)(Object);
> }
> 
> int array[1][2][3];
> 
> ... just reminds me that actually it's not.
> 
> My 2 cents!

1) The C style array declarations have been in D since day 1 :-), they 
aren't a problem to support in the compiler, and are essentially under 
the radar. And I know from experience that they really do help in 
translating C code to D.

2) I had this implemented for a while. The problem is, it sucks. Take a 
look at Object:

class Object
{
     void print();
     string toString();
     hash_t toHash();
     int opCmp(Object o);
     int opEquals(Object o);
}

All these member functions need to be const. Would you rather write:

class Object
{
     void print() const;
     string toString() const;
     hash_t toHash() const;
     int opCmp(Object o) const;
     int opEquals(Object o) const;
}

or:

class Object
{
   const:
     void print();
     string toString();
     hash_t toHash();
     int opCmp(Object o);
     int opEquals(Object o);
}

I'm pretty confident the latter style is much easier on the eyes. It 
also makes for a very visually appealing way to segregate the const 
member functions from the mutating ones. If you've ever looked at a 
complex C++ class, all the const's sprinkled liberally through the 
declarations just make for an ugly, confusing mish-mash.

3) Half of D programmers come from C++. Similarities between the two 
make for much quicker adaption to D.



More information about the Digitalmars-d mailing list