digitalmars.D - D should have a root interface
- Frank Benoit (29/29) Jul 28 2008 // user lib
- Robert Fraser (3/38) Jul 28 2008 Or, you know, just make all instances of interfaces that don't extend
- Frank Benoit (2/42) Jul 28 2008 yes yes yes yes!
- downs (4/49) Jul 28 2008 yes!!
- Bruno Medeiros (10/55) Aug 11 2008 Yes, and this would be a much better solution than having a root
- Neil Vice (3/43) Jul 28 2008 Can not structs implement interfaces? Should they be implicitly castable...
- Frank Benoit (3/48) Jul 28 2008 structs are plain data. They do not have a virtual function table. So
- Bill Baxter (7/16) Jul 28 2008 No, structs cannot implement interfaces, and it makes no sense to cast a
- Jarrett Billingsley (7/9) Jul 28 2008 It's not possible, but I swear I remember W mentioning this sometime. I...
- JAnderson (5/18) Jul 28 2008 Check out the D conference Part 2 of Walter and Andrei talk (at 34m).
- Sean Kelly (4/13) Jul 28 2008 It was a really hacky way to implement contracts for D2. I don't
- Sean Kelly (3/15) Jul 28 2008 Oops, I meant concepts, not contracts.
- Max Samukha (4/47) Jul 28 2008 Structs cannot implement interfaces yet and, unlike C#, D doesn't do
- =?ISO-8859-15?Q?S=F6nke_Ludwig?= (3/43) Jul 28 2008 But what if the object behind the interface is not created from D, but f...
- Robert Fraser (2/46) Jul 29 2008 Fine, extern interfaces also shouldn't cast to object.
- JAnderson (11/47) Jul 29 2008 Personally I think its a mistake to rely on such a low level interface.
- Frank Benoit (4/47) Jul 29 2008 Right, this is an example problem from porting Java code.
- JAnderson (3/51) Jul 29 2008 Maybe we should have a standard IJavaObject :)
// user lib interface List{ void add(Object); } interface ArrayList : List{ void add(Object){} } // calling code List list = ... IFile file = ... // interface type list.add( file ); // compile error list.add( cast(Object) file ); This makes problems when one want to add() an interface instance. A cast to Object is necessary. This is so ugly. If there would be at least an empty root interface for all D interfaces, this can be used for method signatures. // D runtime and used by compiler interface IObject { } // user lib interface List{ void add(Object); void add(IObject); } interface ArrayList : List{ void add(Object){ ... } void add(IObject io){ add(cast(Object)io); } } This would not break any code and helps to make the calling code less casty.
Jul 28 2008
Frank Benoit Wrote:// user lib interface List{ void add(Object); } interface ArrayList : List{ void add(Object){} } // calling code List list = ... IFile file = ... // interface type list.add( file ); // compile error list.add( cast(Object) file ); This makes problems when one want to add() an interface instance. A cast to Object is necessary. This is so ugly. If there would be at least an empty root interface for all D interfaces, this can be used for method signatures. // D runtime and used by compiler interface IObject { } // user lib interface List{ void add(Object); void add(IObject); } interface ArrayList : List{ void add(Object){ ... } void add(IObject io){ add(cast(Object)io); } } This would not break any code and helps to make the calling code less casty.Or, you know, just make all instances of interfaces that don't extend IUnknown implicitly castable to object.
Jul 28 2008
Robert Fraser schrieb:Frank Benoit Wrote:yes yes yes yes!// user lib interface List{ void add(Object); } interface ArrayList : List{ void add(Object){} } // calling code List list = ... IFile file = ... // interface type list.add( file ); // compile error list.add( cast(Object) file ); This makes problems when one want to add() an interface instance. A cast to Object is necessary. This is so ugly. If there would be at least an empty root interface for all D interfaces, this can be used for method signatures. // D runtime and used by compiler interface IObject { } // user lib interface List{ void add(Object); void add(IObject); } interface ArrayList : List{ void add(Object){ ... } void add(IObject io){ add(cast(Object)io); } } This would not break any code and helps to make the calling code less casty.Or, you know, just make all instances of interfaces that don't extend IUnknown implicitly castable to object.
Jul 28 2008
Frank Benoit wrote:Robert Fraser schrieb:yes!! please :( :ahem: strong vote in favor from me.Frank Benoit Wrote:yes yes yes yes!// user lib interface List{ void add(Object); } interface ArrayList : List{ void add(Object){} } // calling code List list = ... IFile file = ... // interface type list.add( file ); // compile error list.add( cast(Object) file ); This makes problems when one want to add() an interface instance. A cast to Object is necessary. This is so ugly. If there would be at least an empty root interface for all D interfaces, this can be used for method signatures. // D runtime and used by compiler interface IObject { } // user lib interface List{ void add(Object); void add(IObject); } interface ArrayList : List{ void add(Object){ ... } void add(IObject io){ add(cast(Object)io); } } This would not break any code and helps to make the calling code less casty.Or, you know, just make all instances of interfaces that don't extend IUnknown implicitly castable to object.
Jul 28 2008
Frank Benoit wrote:Robert Fraser schrieb:Yes, and this would be a much better solution than having a root interface. :) Frankly, I was quite surprised to find out only now that interfaces were not implicitly castable to Object. I knew they were not binary compatible with each other (as they are in Java), but I always thought them to be implicitably castable (whenever type-safe). -- Bruno Medeiros - Software Developer, MSc. in CS/E graduate http://www.prowiki.org/wiki4d/wiki.cgi?BrunoMedeiros#DFrank Benoit Wrote:yes yes yes yes!// user lib interface List{ void add(Object); } interface ArrayList : List{ void add(Object){} } // calling code List list = ... IFile file = ... // interface type list.add( file ); // compile error list.add( cast(Object) file ); This makes problems when one want to add() an interface instance. A cast to Object is necessary. This is so ugly. If there would be at least an empty root interface for all D interfaces, this can be used for method signatures. // D runtime and used by compiler interface IObject { } // user lib interface List{ void add(Object); void add(IObject); } interface ArrayList : List{ void add(Object){ ... } void add(IObject io){ add(cast(Object)io); } } This would not break any code and helps to make the calling code less casty.Or, you know, just make all instances of interfaces that don't extend IUnknown implicitly castable to object.
Aug 11 2008
Robert Fraser wrote:Frank Benoit Wrote:Can not structs implement interfaces? Should they be implicitly castable to Object?// user lib interface List{ void add(Object); } interface ArrayList : List{ void add(Object){} } // calling code List list = ... IFile file = ... // interface type list.add( file ); // compile error list.add( cast(Object) file ); This makes problems when one want to add() an interface instance. A cast to Object is necessary. This is so ugly. If there would be at least an empty root interface for all D interfaces, this can be used for method signatures. // D runtime and used by compiler interface IObject { } // user lib interface List{ void add(Object); void add(IObject); } interface ArrayList : List{ void add(Object){ ... } void add(IObject io){ add(cast(Object)io); } } This would not break any code and helps to make the calling code less casty.Or, you know, just make all instances of interfaces that don't extend IUnknown implicitly castable to object.
Jul 28 2008
Neil Vice schrieb:Robert Fraser wrote:structs are plain data. They do not have a virtual function table. So they are neither compatible to interfaces and not to classes.Frank Benoit Wrote:Can not structs implement interfaces? Should they be implicitly castable to Object?// user lib interface List{ void add(Object); } interface ArrayList : List{ void add(Object){} } // calling code List list = ... IFile file = ... // interface type list.add( file ); // compile error list.add( cast(Object) file ); This makes problems when one want to add() an interface instance. A cast to Object is necessary. This is so ugly. If there would be at least an empty root interface for all D interfaces, this can be used for method signatures. // D runtime and used by compiler interface IObject { } // user lib interface List{ void add(Object); void add(IObject); } interface ArrayList : List{ void add(Object){ ... } void add(IObject io){ add(cast(Object)io); } } This would not break any code and helps to make the calling code less casty.Or, you know, just make all instances of interfaces that don't extend IUnknown implicitly castable to object.
Jul 28 2008
Content-Disposition: inline On Tue, Jul 29, 2008 at 10:48 AM, Neil Vice <sardonicpresence gmail.com>wrote:This would not break any code and helps to make the calling code lessNo, structs cannot implement interfaces, and it makes no sense to cast a struct to Object either implicitly or explicitly. Structs in D are for representing value types and have no virtual methods or inheritance. --bbCan not structs implement interfaces? Should they be implicitly castable to Object?casty.Or, you know, just make all instances of interfaces that don't extend IUnknown implicitly castable to object.
Jul 28 2008
"Neil Vice" <sardonicpresence gmail.com> wrote in message news:g6lstt$2qi4$1 digitalmars.com...Can not structs implement interfaces? Should they be implicitly castable to Object?It's not possible, but I swear I remember W mentioning this sometime. I can't seem to find when he said it though. It might be something that's still in development for D2, but I also remember him saying something about structs that implement interfaces wouldn't be able to be cast to those interface references, so I'm not sure what purpose it'd serve.
Jul 28 2008
Jarrett Billingsley wrote:"Neil Vice" <sardonicpresence gmail.com> wrote in message news:g6lstt$2qi4$1 digitalmars.com...Check out the D conference Part 2 of Walter and Andrei talk (at 34m). http://d.puremagic.com/conference2007/speakers.html Its mainly for templates though. Kinda concept like. -JoelCan not structs implement interfaces? Should they be implicitly castable to Object?It's not possible, but I swear I remember W mentioning this sometime. I can't seem to find when he said it though. It might be something that's still in development for D2, but I also remember him saying something about structs that implement interfaces wouldn't be able to be cast to those interface references, so I'm not sure what purpose it'd serve.
Jul 28 2008
== Quote from Jarrett Billingsley (kb3ctd2 yahoo.com)'s article"Neil Vice" <sardonicpresence gmail.com> wrote in message news:g6lstt$2qi4$1 digitalmars.com...It was a really hacky way to implement contracts for D2. I don't think we'll ever see this feature. SeanCan not structs implement interfaces? Should they be implicitly castable to Object?It's not possible, but I swear I remember W mentioning this sometime. I can't seem to find when he said it though. It might be something that's still in development for D2, but I also remember him saying something about structs that implement interfaces wouldn't be able to be cast to those interface references, so I'm not sure what purpose it'd serve.
Jul 28 2008
== Quote from Sean Kelly (sean invisibleduck.org)'s article== Quote from Jarrett Billingsley (kb3ctd2 yahoo.com)'s articleOops, I meant concepts, not contracts. Sean"Neil Vice" <sardonicpresence gmail.com> wrote in message news:g6lstt$2qi4$1 digitalmars.com...It was a really hacky way to implement contracts for D2. I don't think we'll ever see this feature.Can not structs implement interfaces? Should they be implicitly castable to Object?It's not possible, but I swear I remember W mentioning this sometime. I can't seem to find when he said it though. It might be something that's still in development for D2, but I also remember him saying something about structs that implement interfaces wouldn't be able to be cast to those interface references, so I'm not sure what purpose it'd serve.
Jul 28 2008
On Tue, 29 Jul 2008 09:48:49 +0800, Neil Vice <sardonicpresence gmail.com> wrote:Robert Fraser wrote:automatic boxing/unboxing of value types.Frank Benoit Wrote:Can not structs implement interfaces? Should they be implicitly castable to Object?// user lib interface List{ void add(Object); } interface ArrayList : List{ void add(Object){} } // calling code List list = ... IFile file = ... // interface type list.add( file ); // compile error list.add( cast(Object) file ); This makes problems when one want to add() an interface instance. A cast to Object is necessary. This is so ugly. If there would be at least an empty root interface for all D interfaces, this can be used for method signatures. // D runtime and used by compiler interface IObject { } // user lib interface List{ void add(Object); void add(IObject); } interface ArrayList : List{ void add(Object){ ... } void add(IObject io){ add(cast(Object)io); } } This would not break any code and helps to make the calling code less casty.Or, you know, just make all instances of interfaces that don't extend IUnknown implicitly castable to object.
Jul 28 2008
Robert Fraser wrote:Frank Benoit Wrote:But what if the object behind the interface is not created from D, but from C++ code or anything else? I'd imagine that would be a really nasty pitfall.// user lib interface List{ void add(Object); } interface ArrayList : List{ void add(Object){} } // calling code List list = ... IFile file = ... // interface type list.add( file ); // compile error list.add( cast(Object) file ); This makes problems when one want to add() an interface instance. A cast to Object is necessary. This is so ugly. If there would be at least an empty root interface for all D interfaces, this can be used for method signatures. // D runtime and used by compiler interface IObject { } // user lib interface List{ void add(Object); void add(IObject); } interface ArrayList : List{ void add(Object){ ... } void add(IObject io){ add(cast(Object)io); } } This would not break any code and helps to make the calling code less casty.Or, you know, just make all instances of interfaces that don't extend IUnknown implicitly castable to object.
Jul 28 2008
Sönke Ludwig Wrote:Robert Fraser wrote:Fine, extern interfaces also shouldn't cast to object.Frank Benoit Wrote:But what if the object behind the interface is not created from D, but from C++ code or anything else? I'd imagine that would be a really nasty pitfall.// user lib interface List{ void add(Object); } interface ArrayList : List{ void add(Object){} } // calling code List list = ... IFile file = ... // interface type list.add( file ); // compile error list.add( cast(Object) file ); This makes problems when one want to add() an interface instance. A cast to Object is necessary. This is so ugly. If there would be at least an empty root interface for all D interfaces, this can be used for method signatures. // D runtime and used by compiler interface IObject { } // user lib interface List{ void add(Object); void add(IObject); } interface ArrayList : List{ void add(Object){ ... } void add(IObject io){ add(cast(Object)io); } } This would not break any code and helps to make the calling code less casty.Or, you know, just make all instances of interfaces that don't extend IUnknown implicitly castable to object.
Jul 29 2008
Frank Benoit wrote:// user lib interface List{ void add(Object); } interface ArrayList : List{ void add(Object){} } // calling code List list = ... IFile file = ... // interface type list.add( file ); // compile error list.add( cast(Object) file ); This makes problems when one want to add() an interface instance. A cast to Object is necessary. This is so ugly. If there would be at least an empty root interface for all D interfaces, this can be used for method signatures. // D runtime and used by compiler interface IObject { } // user lib interface List{ void add(Object); void add(IObject); } interface ArrayList : List{ void add(Object){ ... } void add(IObject io){ add(cast(Object)io); } } This would not break any code and helps to make the calling code less casty.Personally I think its a mistake to rely on such a low level interface. I think lists should be done with templates and less general interfaces. I'm not sure that D should be encouraging dangerous The only reason for doing something like this I can think of is if your doing some sort of string print out. Even a factory is better represented in terms of an interface that describes how it will be used. Otherwise some sort of downcast will be needed to pull the object out of the list. Ideally you should never need to downcast. -Joel
Jul 29 2008
JAnderson schrieb:Frank Benoit wrote:Right, this is an example problem from porting Java code. I don't like this suggestion either, but it would be better than nothing. I already posted so often about interface/class compatibility ... :/// user lib interface List{ void add(Object); } interface ArrayList : List{ void add(Object){} } // calling code List list = ... IFile file = ... // interface type list.add( file ); // compile error list.add( cast(Object) file ); This makes problems when one want to add() an interface instance. A cast to Object is necessary. This is so ugly. If there would be at least an empty root interface for all D interfaces, this can be used for method signatures. // D runtime and used by compiler interface IObject { } // user lib interface List{ void add(Object); void add(IObject); } interface ArrayList : List{ void add(Object){ ... } void add(IObject io){ add(cast(Object)io); } } This would not break any code and helps to make the calling code less casty.Personally I think its a mistake to rely on such a low level interface. I think lists should be done with templates and less general interfaces. I'm not sure that D should be encouraging dangerous
Jul 29 2008
Frank Benoit wrote:JAnderson schrieb:Maybe we should have a standard IJavaObject :) -JoelFrank Benoit wrote:Right, this is an example problem from porting Java code. I don't like this suggestion either, but it would be better than nothing. I already posted so often about interface/class compatibility ... :/// user lib interface List{ void add(Object); } interface ArrayList : List{ void add(Object){} } // calling code List list = ... IFile file = ... // interface type list.add( file ); // compile error list.add( cast(Object) file ); This makes problems when one want to add() an interface instance. A cast to Object is necessary. This is so ugly. If there would be at least an empty root interface for all D interfaces, this can be used for method signatures. // D runtime and used by compiler interface IObject { } // user lib interface List{ void add(Object); void add(IObject); } interface ArrayList : List{ void add(Object){ ... } void add(IObject io){ add(cast(Object)io); } } This would not break any code and helps to make the calling code less casty.Personally I think its a mistake to rely on such a low level interface. I think lists should be done with templates and less general interfaces. I'm not sure that D should be encouraging
Jul 29 2008