1 day ago
On Saturday, 1 November 2025 at 13:47:22 UTC, Dejan Lekic wrote:
> On Saturday, 1 November 2025 at 06:41:57 UTC, Peter C wrote:
>> ok. now we have the 'accidental implementation' problem.
>>
>
> There is nothing "accidental" there - you have made the decision to inherit from Base, and should know what that means!

Just because you know what it means, doesn't mean I know what it means.

The compiler sure seems to know what it means.

But it's not an absolute that in this situation that the programmer would know what it means - and I specifically use myself as a case study here ;-)

Also, will the next programmer maintaining your code know what it means?

interface Isomething
{
  void someMethod();
}

class Base
{
    void someMethod() {}
}

class Derived : Base, Isomething
{
   // is Derived fullfilling the semantic requirements of interface contract here?
}

23 hours ago
On Friday, 31 October 2025 at 23:36:57 UTC, Quirin Schroll wrote:
>
> ...
> This is a good idea for nomenclature in documentation, but it doesn't work with the language. You can implement an interface method by inheriting from a class that defines the method without the base class implementing the interface.

If D had a C# like 'explicit' interface declaration:

module myModule;
@safe:
private:

void main()
{

}

interface Isomething
{
    void someMethod();
}

class Base
{

    void someMethod()
    {

    }
}

class Derived : Base, Isomething
{
  // Here, I am intentionally binding the interface requirement
  // to a concrete method, rather than letting the inherited method automatically
  // fulfill the interface contract.

  void ISomething.SomeMethod()
  {
    // This method satisfies the interface, but it's only accessible
    // when the object is cast to the ISomething type.
  }
}

12 hours ago
On Sunday, 2 November 2025 at 00:00:35 UTC, Peter C wrote:
> Just because you know what it means, doesn't mean I know what it means.

I am trying very hard to understand you here - you, as developer who wrote the code, deliberately made a decision to inherit from Base class. This means you _do know_ what it means (what that class does).
12 hours ago
On Sunday, 2 November 2025 at 00:49:36 UTC, Peter C wrote:
> On Friday, 31 October 2025 at 23:36:57 UTC, Quirin Schroll wrote:
>> [...]
>
> If D had a C# like 'explicit' interface declaration:
>
> module myModule;
> @safe:
> private:
>
> void main()
> {
>
> }
>
> interface Isomething
> {
>     void someMethod();
> }
>
> class Base
> {
>
>     void someMethod()
>     {
>
>     }
> }
>
> class Derived : Base, Isomething
> {
>   // Here, I am intentionally binding the interface requirement
>   // to a concrete method, rather than letting the inherited method automatically
>   // fulfill the interface contract.
>
>   void ISomething.SomeMethod()
>   {
>     // This method satisfies the interface, but it's only accessible
>     // when the object is cast to the ISomething type.
>   }
> }

the whole point of it is to not have to cast to interfaces, but just have the type behave a certain way.
just use plain old composition if and alias the methods if you want this.

1 hour ago
On Sunday, 2 November 2025 at 11:33:56 UTC, Dejan Lekic wrote:
> On Sunday, 2 November 2025 at 00:00:35 UTC, Peter C wrote:
>> Just because you know what it means, doesn't mean I know what it means.
>
> I am trying very hard to understand you here - you, as developer who wrote the code, deliberately made a decision to inherit from Base class. This means you _do know_ what it means (what that class does).

There is no indication to me that Base intended to implement the semantic requirements of the interface. Do you understand that?

And yet, Base.someMethod() is considered an implementation of the interface. I understand that the compiler undertands this (because it has the same signature), but really, the compiler is just taking the easiest possible path here.

It's still not clear to *me* (regardless of the rules here) that by simply inherting a method from Base that has the same signature, that it automatically satisfies the semantic requirements of the interface.

The person maintaining this code will likely ask the same question I did - does Derived implement the semantic requirement of the interface, or not?

A C# like explicit interface declaration in D, would have solved this question straight away. The intent would have been clear, and I would have understood immediately that Derived has indeed implemented the semantic requirement of the interface.

D's starting to remind me of that scene in Ghostbusters, where Peter drives up with (what will become) the ghostbusters vehicle. i.e. look promising, but will need a lot of work.

1 2
Next ›   Last »