View mode: basic / threaded / horizontal-split · Log in · Help
February 03, 2012
Re: what is a usage pattern for "static" in an interface?
On 2012-02-03 13:24, dennis luehring wrote:
> Am 03.02.2012 13:10, schrieb dennis luehring:
>> Am 03.02.2012 13:02, schrieb Jonathan M Davis:
>>> C++ doesn't have interfaces, and C# and Java don't allow function
>>> implementations of any kind on interfaces. The same is not true for D.
>>
>> but as you can see in my example - my static function isn't implemented
>> in the interface scope
>>
>> interface test
>> {
>> static void blub();<----
>> }
>>
>> there is no example of an not implemented static in a interface
>>
>>
>
> i think should file an bug report for both

The implementation could come from a different object file. But you 
should get a linker error if it doesn't.

-- 
/Jacob Carlborg
February 03, 2012
Re: what is a usage pattern for "static" in an interface?
Am 03.02.2012 13:34, schrieb bls:
> On 02/03/2012 04:00 AM, Jonathan M Davis wrote:
>>  D interfaces_do_  allow for function implementations under certain
>>  circumstances.
>>
>>  - Jonathan M Davis
>
> A code snippet please.

http://dlang.org/interface.html

interface D
{
  void bar() { } // error, implementation not allowed
  static void foo() { } // ok
  final void abc() { } // ok
}
February 03, 2012
Re: what is a usage pattern for "static" in an interface?
Le 03/02/2012 13:02, Jonathan M Davis a écrit :
> On Friday, February 03, 2012 09:03:21 dennis luehring wrote:
>> Am 03.02.2012 08:40, schrieb Jonathan M Davis:
>>> On Friday, February 03, 2012 08:30:31 dennis luehring wrote:
>>>>   any idea why static could makes sense in an interface? any example?
>>>
>>> The same reason it makes sense in a class. I don't see any difference.
>>
>> that also my first thought - but why do c#, java (and c++) don't allow it?
>
> C++ doesn't have interfaces, and C# and Java don't allow function
> implementations of any kind on interfaces. The same is not true for D.
>

Java will allow it in its next version. This will actually be more 
powerfull that what exists in D.
February 03, 2012
Re: what is a usage pattern for "static" in an interface?
Am 03.02.2012 13:38, schrieb Jacob Carlborg:
> On 2012-02-03 13:24, dennis luehring wrote:
>>  Am 03.02.2012 13:10, schrieb dennis luehring:
>>>  Am 03.02.2012 13:02, schrieb Jonathan M Davis:
>>>>  C++ doesn't have interfaces, and C# and Java don't allow function
>>>>  implementations of any kind on interfaces. The same is not true for D.
>>>
>>>  but as you can see in my example - my static function isn't implemented
>>>  in the interface scope
>>>
>>>  interface test
>>>  {
>>>  static void blub();<----
>>>  }
>>>
>>>  there is no example of an not implemented static in a interface
>>>
>>>
>>
>>  i think should file an bug report for both
>
> The implementation could come from a different object file. But you
> should get a linker error if it doesn't.
>

another problem i've found

interface itest
{
  static void blub(){};
}

class A: itest
{
  void blub(){};
}

class A overrides (silently) the static blub from the interface with an 
normal method

itest it = new A();

A.blub(); // error - not a static
it.blub(); // ok

or

interface itest
{
  static void blub(){}
}

class A: itest
{
  static void blub(){}
}

class A just override blub()
February 03, 2012
Re: what is a usage pattern for "static" in an interface?
Am 03.02.2012 13:55, schrieb deadalnix:
> Le 03/02/2012 13:02, Jonathan M Davis a écrit :
>>  On Friday, February 03, 2012 09:03:21 dennis luehring wrote:
>>>  Am 03.02.2012 08:40, schrieb Jonathan M Davis:
>>>>  On Friday, February 03, 2012 08:30:31 dennis luehring wrote:
>>>>>    any idea why static could makes sense in an interface? any example?
>>>>
>>>>  The same reason it makes sense in a class. I don't see any difference.
>>>
>>>  that also my first thought - but why do c#, java (and c++) don't allow it?
>>
>>  C++ doesn't have interfaces, and C# and Java don't allow function
>>  implementations of any kind on interfaces. The same is not true for D.
>>
>
> Java will allow it in its next version. This will actually be more
> powerfull that what exists in D.

Link?
February 03, 2012
Re: what is a usage pattern for "static" in an interface?
Le 03/02/2012 14:12, dennis luehring a écrit :
> Am 03.02.2012 13:55, schrieb deadalnix:
>> Le 03/02/2012 13:02, Jonathan M Davis a écrit :
>>> On Friday, February 03, 2012 09:03:21 dennis luehring wrote:
>>>> Am 03.02.2012 08:40, schrieb Jonathan M Davis:
>>>>> On Friday, February 03, 2012 08:30:31 dennis luehring wrote:
>>>>>> any idea why static could makes sense in an interface? any example?
>>>>>
>>>>> The same reason it makes sense in a class. I don't see any difference.
>>>>
>>>> that also my first thought - but why do c#, java (and c++) don't
>>>> allow it?
>>>
>>> C++ doesn't have interfaces, and C# and Java don't allow function
>>> implementations of any kind on interfaces. The same is not true for D.
>>>
>>
>> Java will allow it in its next version. This will actually be more
>> powerfull that what exists in D.
>
> Link?

You'll find that conference interesting : 
http://medianetwork.oracle.com/media/show/16999

Also, this link that explain it with code snippet. It is in french, but 
I'm sure you'll understand at least code snippet if you know java : 
http://blog.xebia.fr/2011/10/05/les-methodes-virtuelles-dextension-dans-java-8/

I think this functionnality is awesome, and D should provide a way to 
profide default implementation in interfaces if needed. The most 
important advantage is to allow an API to evolve without requiring the 
whole code using it to be rewritten.

Here is the way to go :
1/ Add the new methods in the interface, and provide default 
implementation using the old API (even if it is non optimal).
2/ Warn and then mark the old API as deprecated.
3/ When the codebase had enough time to comply with the new API, you can 
remove the old API methods.
February 03, 2012
Re: what is a usage pattern for "static" in an interface?
On 02/03/2012 11:40 AM, Paulo Pinto wrote:
>  From OO design it does not make any sense. I was even't aware that this
> is possible in D.
>
> Static methods are intented to be used as what is commonly known as
> class methods in Smalltalk. Methods
> that are attached to the class class, usually known as metaclass. These
> methods are then transversal to
> all instances of a given class and are called by ClassName.Method() .
>
> Interfaces don't have implementations per se, they only describe a set
> of funcionalities that any implementing
> class is obliged to provide. Hence there is no direct implementation and
> no difference between instances and
> metaclasses.
>
> D interfaces seem then to provide a mechanism where implementing classes
> are forced to implement static methods,

Nope.

> but since when calling interface methods the form is always
> Interface.Method(), what is the added benefict to force
> static method implementations?
>
> Which use cases have lead to such decision?
>
> --
> Paulo
>
> "Jonathan M Davis" wrote in message
> news:mailman.298.1328254901.25230.digitalmars-d@puremagic.com...
>
> On Friday, February 03, 2012 08:30:31 dennis luehring wrote:
>> any idea why static could makes sense in an interface? any example?
>
> The same reason it makes sense in a class. I don't see any difference.
>
> - Jonathan M Davis
February 04, 2012
Re: what is a usage pattern for "static" in an interface?
On Fri, 03 Feb 2012 08:30:31 +0100, dennis luehring <dl.soluz@gmx.net>  
wrote:

> like:
>
> public interface test
> {
>    public static void blub();
> }
>
> static class test_static: test
> {
>    private static void blub()
>    {
>       int i = 10;
>    }
> }
>
> int main()
> {
>    test_static.blub();
>
>    return 0;
> }
>
> any idea why static could makes sense in an interface? any example?
>
> another thing:
>
> why can i public "blub" in the interface and private it in the class?

It's a bug of the compiler to ignore unapplicaple attributes.

http://d.puremagic.com/issues/show_bug.cgi?id=3934
http://d.puremagic.com/issues/show_bug.cgi?id=3118

> http://blog.xebia.fr/2011/10/05/les->methodes-virtuelles-dextension-dans-java-8/
> http://cr.openjdk.java.net/~darcy/DefenderMethods.pdf

Allowing default implementations in interfaces is a great to be able to  
extend
interfaces without breaking dependent code and also to simplify class  
implementation.

If override were mandatory in implementation classes we could easily allow  
implementations
in interfaces.
February 04, 2012
Re: what is a usage pattern for "static" in an interface?
Am 04.02.2012, 02:54 Uhr, schrieb Martin Nowak <dawg@dawgfoto.de>:

> If override were mandatory in implementation classes we could easily  
> allow implementations
> in interfaces.

Do you have a good example? Mine are currently all solvable with final  
methods in interfaces, like

	interface ... {
		...
		@property size_t length();
		@property final bool empty() { return length == 0; }
	}
February 04, 2012
Re: what is a usage pattern for "static" in an interface?
On Saturday, 4 February 2012 at 05:01:10 UTC, Marco Leise wrote:
> Am 04.02.2012, 02:54 Uhr, schrieb Martin Nowak 
> <dawg@dawgfoto.de>:
>
>> If override were mandatory in implementation classes we could 
>> easily allow implementations
>> in interfaces.
>
> Do you have a good example? Mine are currently all solvable 
> with final methods in interfaces, like
>
> 	interface ... {
> 		...
> 		@property size_t length();
> 		@property final bool empty() { return length == 0; }
> 	}

There exists std::list implementations in C++ where length is an 
O(n) operation, but empty could still be O(1).
1 2 3
Top | Discussion index | About this forum | D home