D's Destructors are What Scott Meyers Warned Us About
Manu
turkeyman at gmail.com
Wed May 23 19:05:38 UTC 2018
On 23 May 2018 at 10:59, Steven Schveighoffer via Digitalmars-d
<digitalmars-d at puremagic.com> wrote:
> On 5/23/18 1:41 PM, Manu wrote:
>>
>> On 23 May 2018 at 05:38, Steven Schveighoffer via Digitalmars-d
>> <digitalmars-d at puremagic.com> wrote:
>>>
>>> On 5/22/18 10:15 PM, Manu wrote:
>>>>
>>>>
>>>> If you're in the mood to prepare a DIP, I think you should prepare this
>>>> dip:
>>>>
>>>> Support the syntax:
>>>> classInstance.~this();
>>>
>>>
>>>
>>> Isn't this just classInstance.destroy() ?
>>
>>
>> Is everything in object.d globally available? You don't have to import
>> `destroy()` right?
>> My nit-pick is that destroy resets to .init after destruction, which
>> makes it feel like more than a destroy, and that is almost certainly
>> the reason people reach for __xdtor() when they do (ie, they JUST want
>> to destruct).
>> We should probably address that, and then publish a strong recommendation.
>>
>
> I think it's a good idea. Like unsafeDestroy.
I hate the name.
People will constantly reach for the wrong thing.
Such a long name says to me "this isn't the function you're looking
for" in terms of intuition.
For my money it would be:
destroy() <- just destroy
reset() <- destroy and re-init
Or something like that.
Maybe:
class.destruct(); <- destroy without init?
Yeah that. I'll make a PR!
More information about the Digitalmars-d
mailing list