<div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Oct 11, 2024 at 5:36 AM Salih Dincer via Digitalmars-d <<a href="mailto:digitalmars-d@puremagic.com">digitalmars-d@puremagic.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On Thursday, 10 October 2024 at 09:33:21 UTC, Zoadian wrote:<br>
> the fact that you have to add comments shows how bad the syntax <br>
> actually is.<br>
> imaging having them readable like this instead so one doesn't <br>
> have to look up the language documentation to figure out what's <br>
> going on:<br>
> ```<br>
> constructor()<br>
> copy_constructor()<br>
> blit_constructor()<br>
> move_constructor()<br>
> destructor()<br>
<br>
I am surprised by suggestions that would break the code just to <br>
make it look melodious...<br>
<br>
Yes, you are suggesting alternative syntaxes for the move <br>
constructor, which does not officially exist in D. These <br>
suggestions are quite interesting from a language design <br>
perspective and could offer different approaches to usage. <br>
Unfortunately, we are not inventing a new programming language. <br>
So we can only suggest suggestions that are compatible with the <br>
existing one. For technical reasons, `this(S)` will not work.<br>
<br>
IMO, there's any need to discussion. We have only one option. <br>
Just do it and let's not waste time:<br>
<br>
**Move Constructor Syntax: `=this(S)`**<br>
<br>
In the upcoming version of D, we are adding a **move <br>
constructor** to complement the existing **copy constructor** and <br>
**destructor**. Just as destructors are invoked with `~this()`, <br>
move constructors will now be expressed using the intuitive and <br>
concise syntax `=this(S)`.<br>
<br>
The `=this(S)` move constructor enables efficient transfer of <br>
resources from one object to another without the overhead of <br>
copying. When an object is moved, its internal resources (such as <br>
memory pointers) are transferred to the new object, and the <br>
original object is left in a safe, "moved-from" state, often with <br>
nullified or reset values.<br>
<br>
**Why =this(S)?**<br>
<br>
**Symmetry with Destructor:** Just like the destructor `~this()`, <br>
which frees up resources, the move constructor `=this(S)` <br>
transfers ownership of resources. This symmetry makes the syntax <br>
easy to understand and use.<br>
<br>
**Efficiency:** Moving objects is more efficient than copying <br>
because it avoids unnecessary memory allocations or deep copies. <br>
In the move constructor, resources are transferred directly, <br>
leaving the original object in a state where its resources can <br>
safely be discarded.<br>
<br>
Don't you want to have what is written above? Let's increase the <br>
performance as soon as possible because this has gone on for too <br>
long! I have another question at this stage:<br>
<br>
**Question About How Destructors and Move Constructors Work <br>
Together:**<br>
<br>
Since the original object is invalidated, does the destructor <br>
(`~this()`) know that it has nothing to free when it is called on <br>
the moved object?<br>
<br>
SDB@79<br></blockquote><div><br></div><div>My problem with =this(S) is that from a linguistic point of view it's ambiguous. the = could just as reasonably apply to any type of constructor. As a new user of the language the only way you can figure out what it does is to read the documentation and memorise. That's something you want to avoid when creating new syntax if at all possible.<br></div></div></div>