Thread overview
Forward Declaration
Mar 16, 2007
Satish
Mar 16, 2007
Derek Parnell
Mar 16, 2007
Henning Hasemann
Mar 17, 2007
BCS
March 16, 2007
Hello D Programmers

As a C++ programmer I have written classes such as

class Object{
  public:
    Object(int value1);
};

Object::Object(int value1){}

My terminology will be wrong here but I really enjoy separating the declaration and implementation of class members.


Yes in C++ also allows such declaration:
class Object{
  public:
    Object(int value1){return 100;}
    long server(){
     //several lines of code 1
     //several lines of code 2
     //several lines of code 3
     //several lines of code 4
    }
};


Why doesn't 'D' allow to separate method definition and method implementation
such as
<
     Object::Object(int value1){
        //my implementation
     }
>


If becomes tough not hard to debug classes if/when there is closing curly bracket if it missing.


I seem to more time ensure that I don't miss any opening and closing braces.


Thanks for the advice.

Satish
March 16, 2007
On Fri, 16 Mar 2007 03:37:07 +0000 (UTC), Satish wrote:

> Hello D Programmers
> 
> As a C++ programmer I have written classes such as
> 
> class Object{
>   public:
>     Object(int value1);
> };
> 
> Object::Object(int value1){}
> 
> My terminology will be wrong here but I really enjoy separating the declaration and implementation of class members.

Why?

> Yes in C++ also allows such declaration:
> class Object{
>   public:
>     Object(int value1){return 100;}
>     long server(){
>      //several lines of code 1
>      //several lines of code 2
>      //several lines of code 3
>      //several lines of code 4
>     }
> };


What is the difference between ...

  class Object{
    public:
      Object(int value1){return 100;}
      long server(){
       //several lines of code 1
       //several lines of code 2
       //several lines of code 3
       //several lines of code 4
      }
  };


and

 class Object{
   public:
     Object(int value1);
     long server();
 };

 Object::Object(int value1){return 100;}
 long Object::server(){
      //several lines of code 1
      //several lines of code 2
      //several lines of code 3
      //several lines of code 4
     }



> Why doesn't 'D' allow to separate method definition and method implementation
> such as
> <
>      Object::Object(int value1){
>         //my implementation
>      }

Actually it does allow that style of coding ...

  // define (list) the methods to be implemented.
  interface XXX
  {
        long server();
  }

  // now implement them.
  class OBJect : XXX
  {
      long server() {
      //several lines of code 1
      //several lines of code 2
      //several lines of code 3
      //several lines of code 4
     }
   }

> 
> If becomes tough not hard to debug classes if/when there is closing curly bracket if it missing.
> 
> I seem to more time ensure that I don't miss any opening and closing braces.

Both styles have the same brace matching issue so I don't see why you might think this is a problem with the D style.

-- 
Derek
(skype: derek.j.parnell)
Melbourne, Australia
"Justice for David Hicks!"
16/03/2007 3:29:56 PM
March 16, 2007
There are .di-files which just hold the information about a class
(in fact the whole module) thats needed to *use* it, IIRC.
These look similar to header files in C++ and serve a similar purpose
so it seems to me, so maybe they are some help to you, getting
an overview over your classes or whatever.

Henning

-- 
v4sw7Yhw4ln0pr7Ock2/3ma7uLw5Xm0l6/7DGKi2e6t6ELNSTVXb7AHIMOen5a2Xs5Mr2g5ACPR hackerkey.com
March 17, 2007
Reply to Satish,

> Hello D Programmers
> 
[...]
> Why doesn't 'D' allow to separate method definition and method
> implementation

IIRC it is for the same reason that D doesn't have prototypes and hand made headers (.di's are generated by DMD). The issue is that having duplicate information can cause problems if only one is updated.

[...]
> 
> Thanks for the advice.
> 
> Satish
>