Structs as reference types?
sighoya
sighoya at gmail.com
Sun May 30 11:17:03 UTC 2021
On Sunday, 30 May 2021 at 07:04:29 UTC, Alexandru Ermicioi wrote:
> From the looks of the request, what he wanted is to have mainly
> reference semantics, which classes already have.
My gut feeling is that structs are in favor toward classes. Both
aren't really interconvertible and if you don't use templated
code you have to decide between structs, classes and interfaces.
Examples are the container structures in D which seem to be
stucts. We may say that passing them by value is optimized out,
however value fields have still to be copied in certain cases
which is unnecessary.
Passing them by ref is fine but that holds only for stack
allocated structs? Moreover, there are no `ref T` types making it
hard to instantiate type parameters with ref structures.
For heap structs, we have pointers, but it sucks to create
aliases all the time to hide the pointer in the name of the
pointer struct.
> It would be nice if the proto object proposal would get
> implemented. It would cleanse a bit the Object hierarchy and
> would allow use classes as structs (well still a bit fatter)
> without extern (c++).
Interesting, did you have a link.
Further, I'm also in favor of adding:
```D
ref struct S
{
int i;
}
```
which wouldn't be covered by the proposal?
Really, I would like to make structs and classes more equatable
to each other, switching between them sucks.
More information about the Digitalmars-d
mailing list