Discussion Thread: DIP 1042--ProtoObject--Community Review Round 1

tsbockman thomas.bockman at gmail.com
Fri Jan 14 03:38:28 UTC 2022


On Monday, 10 January 2022 at 13:48:14 UTC, Mike Parker wrote:
> This is the discussion thread for the first round of Community 
> Review of DIP 1042, "ProtoObject":
>
> https://github.com/dlang/DIPs/blob/2e6d428f42b879c0220ae6adb675164e3ce3803c/DIPs/DIP1042.md

One issue with this DIP that I haven't noticed anyone else raise 
yet is interface bloat. Each interface directly implemented by a 
class or any of its super classes adds `size_t.sizeof` to the 
instance size:

```D
module app;

import std.stdio : writeln;

interface Stringify { }
interface Hash { }
interface Ordered { }
interface Equals { }

class D : Stringify, Hash, Ordered, Equals { }

void main() {
     writeln("Object instance size: ", __traits(classInstanceSize, 
Object));
     writeln("D instance size: ", __traits(classInstanceSize, D));
}
```

Output:
```
Object instance size: 16
D instance size: 48
```

We care enough about minimizing instance size to fret about 8 
bytes wasted on an unused mutex, but then burden all new-style 
classes that need full compatibility with the standard library 
with up to 32 bytes of interface implementations. This does not 
seem like an improvement to me.

Single method interfaces are an anti-pattern for lightweight 
classes, given how D implements interfaces.


More information about the Digitalmars-d mailing list