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

apz28 home at home.com
Sat Jan 15 17:45:16 UTC 2022


On Monday, 10 January 2022 at 13:48:14 UTC, Mike Parker wrote:
> ## Discussion Thread
>
> 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
>

Currently 'struct' can be used as below. So why Object/class not 
behave the same.
They are both aggregated type

     struct Foo
     {
         int i;
     }

     void main()
     {
         import std.stdio;

         Foo a, b;
         writeln("a=", a);
         bool e = a == b;
         writeln("equ=", e);

         string[Foo] as;
         as[a] = "a";
         writeln("as[a]=", as[a]);

         //int c = a > b; -> Error: need member function `opCmp()` 
for struct `Foo` to compare
         //writeln("cmp=", c);
     }


1. opEquals, opCmp, toHash, toString
Get rid of these Object build in functions
1a. If a object is not defined one, do same as struct;
since it does not have any member, use identity
Object a, b;
a == b; // Compare using 'a is b' construct
Note:
Can search for virtual function with opEquals name -> if found 
use it -> slow;
assume attributes are same as of now

1b. If a object is not defined one, do same as struct
class A { int a; }
A a, b;
a == b;
Note:
Can search for virtual function with opEquals name -> if found 
use it -> slow;
assume attributes are same as of now

1c. Defined one -> use it
class B { int a; bool opEquals(B rhs) {...} }
B a, b;
a == b;

2. monitor member for synchronized(this)
2a. Get rid of this build in member
2b. If there is a call, synchronized(this) {}, create one global 
monitor (mutex) per class type using the module name where it is 
defined and use it. Document it as such. Most of the usage for 
this construct is one global instance.
2c. 'synchronized' can be extended to send in monitor (mutex) 
object such as synchronized(this, existing_monitor...) {}

Cheers - Happy coding


More information about the Digitalmars-d mailing list