Thread overview | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
August 30, 2001 D Project Status | ||||
---|---|---|---|---|
| ||||
I would like to hear from the persons responsible for bringing the world "D" the status of the project, compiler, and the amount of effort being put into play to expand and define the language. While it looks to be quite promising, there is something sweet about a language that has existed for 20+ years and is still being actively used. This is largely due to the amount of effort (from many, many people) into C. I'm anxious to see if this is vaporware, or if we're dealing something that is serious enough to contribute time to.
--
Michael Lee Yohe (myohe+USENET@redhat.com)
Software Developer, Engineering Services
Red Hat, Inc.
QUIPd 0.12:
-> One man with courage is a majority.
-> - Thomas Jefferson (1743-1826)
|
August 30, 2001 Re: D Project Status | ||||
---|---|---|---|---|
| ||||
Posted in reply to Michael Lee Yohe | The compiler exists, but is a bit buggy. The runtime library is a bit embryonic. The other tools - linker, make, etc., are all done & mature since they come from the C/C++ compiler.
I'm currently working on building a better garbage collector.
Michael Lee Yohe wrote in message <3B8D9A7A.90404@redhat.com>...
>
>I would like to hear from the persons responsible for bringing the world "D" the status of the project, compiler, and the amount of effort being put into play to expand and define the language. While it looks to be quite promising, there is something sweet about a language that has existed for 20+ years and is still being actively used. This is largely due to the amount of effort (from many, many people) into C. I'm anxious to see if this is vaporware, or if we're dealing something that is serious enough to contribute time to.
|
August 30, 2001 How to avoid code duplication in D? MI/CI/delegation/C&P? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter | Admittedly Java's single inheritance is easy to implement, and simple to use. But it does have some defect which sometimes force a programmer to duplicate code by 'copy & paste': Suppose I have two classes 'Car' and 'Dog', which *have already inherited* from some more important classes 'Vehicle' and 'Animal' respectively (let's assume that 'Vehicle' and 'Dog' do not have a common modifiable ancestor); now I want both these two classes to implement another interface 'Idable', how can I do it? Answer: Java: Copy & Paste, code duplication !!! C++: Multiple inheritance, no code duplication C++: Textual code inclusion, no code duplication Eiffel: Multiple inheritance, no code duplication Sather: Semantic code inclusion, no code duplication Kiev: MI by delegation, no code duplication so what's the solution D can provide? D: ??? code duplication ??? D borrowed DbC from Eiffel, perhaps it also worth to check the multiple inheritance mechanism of Eiffel, which is much cleaner than C++ (by renaming and redefinition). Or if you still feel strongly against MI, maybe you can also consider Sather's semantic code inclusion, or Kiev's forward-able delegation? Let me know your thoughts on this. YuQian Sample code: /*********************************************************************** Java: Copy & Paste, code duplication ***********************************************************************/ interface Idable { public void setId(int i); public void getId(); } class Car extends Vehicle implements Idable { private int id; public void setId(int i) { id = i; } public void getId() { return i; } } class Dog extends Animal implements Idable { private int id; // copy public void setId(int i) { id = i; } // & public void getId() { return i; } // paste! } /*********************************************************************** Kiev: Multiple inheritance by delegation, no code duplication ***********************************************************************/ class Id { private int id; public void setId(int i) { id = i; } public void getId() { return i; } } class Car extends Vehicle { forward public Id myId; // forward car.getId() to car.myId.getId() } class Dog extends Animal { forward public Id myId; // forward dog.getId() to dog.myId.getId() } /*********************************************************************** C++: Multiple inheritance, no code duplication ***********************************************************************/ class Idable { private: int id; public: void setId(int i) { id = i; } void getId() { return i; } }; class Car: public Vehicle, Idable {}; class Dog: public Animal, Idable {}; /*********************************************************************** C++: Textual code inclusion, no code duplication ***********************************************************************/ //--- begin file: id.ci --- private: int id; public: void setId(int i) { id = i; } void getId() { return i; } //--- end file: id.ci --- class Car: public Vehicle { #include "id.ci" }; class Dog: public Animal { #include "id.ci" }; |
August 30, 2001 Re: How to avoid code duplication in D? MI/CI/delegation/C&P? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Yu Qian Zhou | The way to do it is to use interfaces: class Car : Vehicle, Idable { } Base classes after the first base class are interface classes. -Walter ----------------------------------------------------------------- Yu Qian Zhou wrote in message ... Admittedly Java's single inheritance is easy to implement, and simple to use. But it does have some defect which sometimes force a programmer to duplicate code by 'copy & paste': Suppose I have two classes 'Car' and 'Dog', which *have already inherited* from some more important classes 'Vehicle' and 'Animal' respectively (let's assume that 'Vehicle' and 'Dog' do not have a common modifiable ancestor); now I want both these two classes to implement another interface 'Idable', how can I do it? Answer: Java: Copy & Paste, code duplication !!! C++: Multiple inheritance, no code duplication C++: Textual code inclusion, no code duplication Eiffel: Multiple inheritance, no code duplication Sather: Semantic code inclusion, no code duplication Kiev: MI by delegation, no code duplication so what's the solution D can provide? D: ??? code duplication ??? D borrowed DbC from Eiffel, perhaps it also worth to check the multiple inheritance mechanism of Eiffel, which is much cleaner than C++ (by renaming and redefinition). Or if you still feel strongly against MI, maybe you can also consider Sather's semantic code inclusion, or Kiev's forward-able delegation? Let me know your thoughts on this. YuQian Sample code: /*********************************************************************** Java: Copy & Paste, code duplication ***********************************************************************/ interface Idable { public void setId(int i); public void getId(); } class Car extends Vehicle implements Idable { private int id; public void setId(int i) { id = i; } public void getId() { return i; } } class Dog extends Animal implements Idable { private int id; // copy public void setId(int i) { id = i; } // & public void getId() { return i; } // paste! } /*********************************************************************** Kiev: Multiple inheritance by delegation, no code duplication ***********************************************************************/ class Id { private int id; public void setId(int i) { id = i; } public void getId() { return i; } } class Car extends Vehicle { forward public Id myId; // forward car.getId() to car.myId.getId() } class Dog extends Animal { forward public Id myId; // forward dog.getId() to dog.myId.getId() } /*********************************************************************** C++: Multiple inheritance, no code duplication ***********************************************************************/ class Idable { private: int id; public: void setId(int i) { id = i; } void getId() { return i; } }; class Car: public Vehicle, Idable {}; class Dog: public Animal, Idable {}; /*********************************************************************** C++: Textual code inclusion, no code duplication ***********************************************************************/ //--- begin file: id.ci --- private: int id; public: void setId(int i) { id = i; } void getId() { return i; } //--- end file: id.ci --- class Car: public Vehicle { #include "id.ci" }; class Dog: public Animal { #include "id.ci" }; |
August 30, 2001 Re: How to avoid code duplication in D? MI/CI/delegation/C&P? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Yu Qian Zhou | I believe the D way is code duplication. I personally don't like this,
but it was a design decision in order to prevent the inheritance mess
that C++ owes us an apology for. I know C++'s syntax and semantics are
rather nasty and I hear it makes the compiler internals a mess so I
can't complain if MI is left out. I just dislike how some folk pretend
that there isn't a loss of functionality without MI.
I don't know if D will support MI since there has been a strong
reaction against, but if you know of a better way that it could be
implemented without sacrificing the other design goals of D (including
an easy to implement compiler), I love to hear it. Since the time that
I only knew fortran 77 and Commodore basic, I've want MI functionality.
I just didn't know what it was called until I learn C++.
Dan
Yu Qian Zhou wrote:
>
> Admittedly Java's single inheritance is easy to implement, and simple to use. But it does have some defect which sometimes force a programmer to duplicate code by 'copy & paste':
>
> Suppose I have two classes 'Car' and 'Dog', which *have already inherited* from some more important classes 'Vehicle' and 'Animal' respectively (let's assume that 'Vehicle' and 'Dog' do not have a common modifiable ancestor); now I want both these two classes to implement another interface 'Idable', how can I do it?
>
> Answer:
> Java: Copy & Paste, code duplication !!!
> C++: Multiple inheritance, no code duplication
> C++: Textual code inclusion, no code duplication
> Eiffel: Multiple inheritance, no code duplication
> Sather: Semantic code inclusion, no code duplication
> Kiev: MI by delegation, no code duplication
>
> so what's the solution D can provide?
>
> D: ??? code duplication ???
>
> D borrowed DbC from Eiffel, perhaps it also worth to check the multiple inheritance mechanism of Eiffel, which is much cleaner than C++ (by renaming and redefinition).
>
> Or if you still feel strongly against MI, maybe you can also consider Sather's semantic code inclusion, or Kiev's forward-able delegation?
>
> Let me know your thoughts on this.
>
> YuQian
>
> Sample code:
> /***********************************************************************
> Java: Copy & Paste, code duplication
> ***********************************************************************/
> interface Idable
> {
> public void setId(int i);
> public void getId();
> }
>
> class Car
> extends Vehicle
> implements Idable
> {
> private int id;
> public void setId(int i) { id = i; }
> public void getId() { return i; }
> }
>
> class Dog
> extends Animal
> implements Idable
> {
> private int id; // copy
> public void setId(int i) { id = i; } // &
> public void getId() { return i; } // paste!
> }
>
> /***********************************************************************
> Kiev: Multiple inheritance by delegation, no code duplication
> ***********************************************************************/
> class Id
> {
> private int id;
> public void setId(int i) { id = i; }
> public void getId() { return i; }
> }
>
> class Car
> extends Vehicle
> {
> forward public Id myId; // forward car.getId() to car.myId.getId()
> }
>
> class Dog
> extends Animal
> {
> forward public Id myId; // forward dog.getId() to dog.myId.getId()
> }
>
> /***********************************************************************
> C++: Multiple inheritance, no code duplication
> ***********************************************************************/
> class Idable
> {
> private: int id;
> public:
> void setId(int i) { id = i; }
> void getId() { return i; }
> };
>
> class Car: public Vehicle, Idable {};
> class Dog: public Animal, Idable {};
>
> /***********************************************************************
> C++: Textual code inclusion, no code duplication
> ***********************************************************************/
>
> //--- begin file: id.ci ---
> private: int id;
> public:
> void setId(int i) { id = i; }
> void getId() { return i; }
> //--- end file: id.ci ---
>
> class Car: public Vehicle
> {
> #include "id.ci"
> };
>
> class Dog: public Animal
> {
> #include "id.ci"
> };
|
August 30, 2001 Re: How to avoid code duplication in D? MI/CI/delegation/C&P? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter | Walter wrote:
>
> The way to do it is to use interfaces:
>
> class Car : Vehicle, Idable
> {
> }
>
> Base classes after the first base class are interface classes.
>
> -Walter
Now I'm confused. Can a class inherit implementation code from an interface? If so then I've lost the difference between an interface and multiple inheritance. This also doesn't handle the case where Vehicle and Idable are existing classes (from a library?) that you would rather reuse instead of re-writing.
Dan
|
August 30, 2001 Re: How to avoid code duplication in D? MI/CI/delegation/C&P? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter |
> The way to do it is to use interfaces:
>
> class Car : Vehicle, Idable
> {
> }
>
> Base classes after the first base class are interface classes.
>
>-Walter
What exactly do you mean?
"The way to do it is to use interfaces ... "
... to *introduce* code duplication by Copy&Paste like Java ?
But my question is
"How to *avoid* ..."
... code duplication in D ?
:-)
YuQian
|
August 30, 2001 Re: How to avoid code duplication in D? MI/CI/delegation/C&P? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter | Interfaces are fine and dandy, but the problem is, an interface doesn't carry any *code* with it. Just an interface spec. A Java example: interface A { void DoRight(int a); // Declares that any class that implements A // will provide DoRight. No implementation. } class Z implements A { void DoRight(int a) { // Imagine here 160 lines of complex implementation code. } } class Y implements A { void DoRight(int a) { // 160 lines of complex implementation code. // No matter that it may be *identical* to Z.DoRight... } } Duplication of source code. The worst possible thing for maintenance. A way to solve this in Java is to declare *another* class... class H { public void DoRight(int a) { // 160 lines of, well, you know } } class Z implements A { H helper = new H; public void DoRight(int a) { helper.DoRight(a); } } class Y implements A { H helper = new H; void DoRight(int a) { helper.DoRight(a); } } This is less convenient than multiple inheritance. This could be alleviated if A.DoRight could have a default implementation. But since an interface cannot declare any instance variables, this may be somewhat troublesome. Why not allow interfaces in D to have instance data, and interface methods to have implementations? Then it would be as convenient as multiple inheritance. Interfaces would still be distinct from classes, so it's not *quite* M-I. "Walter" <walter@digitalmars.com> wrote in message news:9mkido$q2i$1@digitaldaemon.com... > The way to do it is to use interfaces: > > class Car : Vehicle, Idable > { > } > > Base classes after the first base class are interface classes. > > -Walter > > ----------------------------------------------------------------- > > Yu Qian Zhou wrote in message ... > > Admittedly Java's single inheritance is easy to implement, and simple to use. But it does have some defect which sometimes force a programmer to duplicate code by 'copy & paste': > > Suppose I have two classes 'Car' and 'Dog', which *have already inherited* from some more important classes 'Vehicle' and 'Animal' respectively (let's assume that 'Vehicle' and 'Dog' do not have a common modifiable ancestor); now I want both these two classes to implement another interface 'Idable', how can I do it? > > Answer: > Java: Copy & Paste, code duplication !!! > C++: Multiple inheritance, no code duplication > C++: Textual code inclusion, no code duplication > Eiffel: Multiple inheritance, no code duplication > Sather: Semantic code inclusion, no code duplication > Kiev: MI by delegation, no code duplication > > so what's the solution D can provide? > > D: ??? code duplication ??? > -- Richard Krehbiel, Arlington, VA, USA rich@kastle.com (work) or krehbiel3@home.com (personal) |
August 30, 2001 Re: How to avoid code duplication in D? MI/CI/delegation/C&P? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Dan Hursh | > I believe the D way is code duplication. I personally don't like this,
> but it was a design decision in order to prevent the inheritance mess
> that C++ owes us an apology for. I know C++'s syntax and semantics are
> rather nasty and I hear it makes the compiler internals a mess so I
> can't complain if MI is left out. I just dislike how some folk pretend
> that there isn't a loss of functionality without MI.
> I don't know if D will support MI since there has been a strong
> reaction against, but if you know of a better way that it could be
> implemented without sacrificing the other design goals of D (including
> an easy to implement compiler), I love to hear it. Since the time that
> I only knew fortran 77 and Commodore basic, I've want MI functionality. I just didn't know what it was called until I learn C++.
I was thinking about this this morning... you *do* lose a nice feature without MI. The real reason that I think that's the case is because it's a bitch to get it right. There are so may cases of conflicting functions... how do you resolve them and know which function to call?
Suppose classes A and B both define foo(). C inherits from both A and B, which one do you inherit? What if foo() in A and B were redefined from a common ancestor, Z? What if one of them is final? There's just too much to think about.
Here's my thought: What about allowing MI, as long as there are *no* conflicts? None. Whatsoever. If there are, it's an error. That allows the useful part of MI without getting into the mess.
Now, if anyone has a good way of resolving conflicts (I hear Eiffel is good at that) I think we'd all be willing to hear it. But disallowing conflicts shouldn't affect the compiler too much (it just fills in the vtable it was going to leave blank), and it gives ua a nice feature to play with.
Comments on that?
Eric
|
August 30, 2001 Re: How to avoid code duplication in D? MI/CI/delegation/C&P? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Richard Krehbiel | Unfortunately, the helper class is the way to factor out the common code. Another way is to embed an instance of A as a member of Y and Z. -Walter "Richard Krehbiel" <rich@kastle.com> wrote in message news:9ml9gr$1844$1@digitaldaemon.com... > Interfaces are fine and dandy, but the problem is, an interface doesn't carry any *code* with it. Just an interface spec. > > A Java example: > > interface A > { > void DoRight(int a); // Declares that any class that implements A > // will provide DoRight. No implementation. > } > > class Z implements A > { > void DoRight(int a) > { > // Imagine here 160 lines of complex implementation code. > } > } > > class Y implements A > { > void DoRight(int a) > { > // 160 lines of complex implementation code. > // No matter that it may be *identical* to Z.DoRight... > } > } > > Duplication of source code. The worst possible thing for maintenance. > > A way to solve this in Java is to declare *another* class... > > class H > { > public void DoRight(int a) > { > // 160 lines of, well, you know > } > } > > class Z implements A > { > H helper = new H; > public void DoRight(int a) > { > helper.DoRight(a); > } > } > > class Y implements A > { > H helper = new H; > void DoRight(int a) > { > helper.DoRight(a); > } > } > > This is less convenient than multiple inheritance. > > This could be alleviated if A.DoRight could have a default implementation. But since an interface cannot declare any instance variables, this may be somewhat troublesome. > > Why not allow interfaces in D to have instance data, and interface methods to have implementations? Then it would be as convenient as multiple inheritance. Interfaces would still be distinct from classes, so it's not *quite* M-I. > > "Walter" <walter@digitalmars.com> wrote in message news:9mkido$q2i$1@digitaldaemon.com... > > The way to do it is to use interfaces: > > > > class Car : Vehicle, Idable > > { > > } > > > > Base classes after the first base class are interface classes. > > > > -Walter > > > > ----------------------------------------------------------------- > > > > Yu Qian Zhou wrote in message ... > > > > Admittedly Java's single inheritance is easy to implement, and simple to use. But it does have some defect which sometimes force a programmer to duplicate code by 'copy & paste': > > > > Suppose I have two classes 'Car' and 'Dog', which *have already inherited* > > from some more important classes 'Vehicle' and 'Animal' respectively (let's assume that 'Vehicle' and 'Dog' do not have a common modifiable ancestor); now I want both these two classes to implement another interface 'Idable', how can I do it? > > > > Answer: > > Java: Copy & Paste, code duplication !!! > > C++: Multiple inheritance, no code duplication > > C++: Textual code inclusion, no code duplication > > Eiffel: Multiple inheritance, no code duplication > > Sather: Semantic code inclusion, no code duplication > > Kiev: MI by delegation, no code duplication > > > > so what's the solution D can provide? > > > > D: ??? code duplication ??? > > > > -- > Richard Krehbiel, Arlington, VA, USA > rich@kastle.com (work) or krehbiel3@home.com (personal) > > |
Copyright © 1999-2021 by the D Language Foundation