Random thought: Alternative stuct

Mike Franklin slavo5150 at yahoo.com
Thu Sep 6 05:17:02 UTC 2018


On Wednesday, 5 September 2018 at 18:41:15 UTC, Jacob Carlborg 
wrote:
> On 2018-09-04 06:03, Mike Franklin wrote:

> For that it needs to support all the features as classes do 
> today. In that case, what would be the difference compared to 
> classes?

Indeed, the idea is that structs, with a few additional features 
added to the language, should be able to fill the role classes 
fill today.

Polymorphism can be achieved in the library using methods similar 
to what Sarn demonstrated in the article I linked previously.  
Features like mixins can cut down on the boilerplate; other 
boilerplate-removing features would likely be needed.  
Multiple-alias-this and some form of `protected` for structs 
would be examples of additional features that would help to 
implement class-like behavior; again, others would also likely be 
needed.

Reference semantics can be achieved much like C++ does today with 
it's smart pointers and things like `T&`.  For example, D might 
have `GC<T>` for garbage-collected types, `RC<T>` for reference 
counted types, etc, so the ownership and reference semantics are 
delegated to a container type in concert with DIP1000-like 
features of some kind.

In general, classes, to me, are looking more and more like syntax 
sugar over existing fundamental language features, and I think 
with the right supplemental language features for reducing 
boilerplate and encapsulate details, something very much like 
classes can be implemented in the library.  I'm just thinking 
out-loud though.  I doubt something like this will happen, 
especially without me or someone else demonstrating such a thing 
with a thorough proof-of-concept implementation.

Mike



More information about the Digitalmars-d mailing list