Re: D's Destructors are What Scott Meyers Warned Us About

2018-07-08 Thread 12345swordy via Digitalmars-d
On Monday, 9 July 2018 at 02:10:27 UTC, sarn wrote: On Monday, 9 July 2018 at 01:19:28 UTC, Mike Franklin wrote: In the context of your blog post at https://theartofmachinery.com/2018/05/27/cpp_classes_in_betterc.html, I'm wondering if the changes in 2.081 help matters at all: I'm wondering if

Re: D's Destructors are What Scott Meyers Warned Us About

2018-07-08 Thread sarn via Digitalmars-d
On Monday, 9 July 2018 at 01:19:28 UTC, Mike Franklin wrote: In the context of your blog post at https://theartofmachinery.com/2018/05/27/cpp_classes_in_betterc.html, I'm wondering if the changes in 2.081 help matters at all: I'm wondering if any of the changes in 2.081 improves the situation

Re: D's Destructors are What Scott Meyers Warned Us About

2018-07-08 Thread Mike Franklin via Digitalmars-d
On Wednesday, 23 May 2018 at 01:59:50 UTC, sarn wrote: (I'm referring to Scott's 2014 DConf talk: https://www.youtube.com/watch?v=KAWA1DuvCnQ) I was actually preparing a DIP about this when Manu posted to the forums about his own related problems with C++ interop. I traced a bug in some of

Re: D's Destructors are What Scott Meyers Warned Us About

2018-05-30 Thread sarn via Digitalmars-d
On Monday, 28 May 2018 at 22:53:03 UTC, 12345swordy wrote: Interesting... You don't mind me asking your assistance on writing DIP on this? I have one set up already, and I needed help as 1.) This is my first time writing a DIP 2.) I don't know what main course of action to take regarding

Re: D's Destructors are What Scott Meyers Warned Us About

2018-05-28 Thread 12345swordy via Digitalmars-d
On Monday, 28 May 2018 at 22:37:01 UTC, sarn wrote: On Monday, 28 May 2018 at 20:13:47 UTC, 12345swordy wrote: [...] Code using destroy() can still use destroy(). Otherwise, __vdtor would be callable in the same way that __dtor and __xdtor are. [...] Interesting... You don't mind me

Re: D's Destructors are What Scott Meyers Warned Us About

2018-05-28 Thread sarn via Digitalmars-d
On Monday, 28 May 2018 at 20:13:47 UTC, 12345swordy wrote: How is __vdtor is going to be called, via destroy or via directly? Code using destroy() can still use destroy(). Otherwise, __vdtor would be callable in the same way that __dtor and __xdtor are. The plan is to have a better, safer,

Re: D's Destructors are What Scott Meyers Warned Us About

2018-05-28 Thread 12345swordy via Digitalmars-d
On Monday, 28 May 2018 at 04:26:02 UTC, sarn wrote: On Sunday, 27 May 2018 at 22:27:52 UTC, sarn wrote: I've been thinking this through a bit, and here's what I've got so far: Here's a tweak that should be implementable without any language changes: Instead of trying to detect an empty

Re: D's Destructors are What Scott Meyers Warned Us About

2018-05-27 Thread sarn via Digitalmars-d
On Sunday, 27 May 2018 at 22:27:52 UTC, sarn wrote: I've been thinking this through a bit, and here's what I've got so far: Here's a tweak that should be implementable without any language changes: Instead of trying to detect an empty destructor, we use a UDA on the class --- call it

Re: D's Destructors are What Scott Meyers Warned Us About

2018-05-27 Thread sarn via Digitalmars-d
On Sunday, 27 May 2018 at 09:55:56 UTC, Mike Franklin wrote: TypeInfo has become my nemesis. I've been trying to replace runtime hooks that depend on TypeInfo with templates that can get their information at compile-time, but I'm running into all sorts of problems. e.g. Did you know

Re: D's Destructors are What Scott Meyers Warned Us About

2018-05-27 Thread sarn via Digitalmars-d
On Sunday, 27 May 2018 at 21:11:42 UTC, 12345swordy wrote: On Sunday, 27 May 2018 at 18:55:41 UTC, Mike Franklin wrote: And see this talk for a demonstration of the benefits https://www.youtube.com/watch?v=endKC3fDxqs Mike Can you actually reply to me instead of saying "read/watch this"?

Re: D's Destructors are What Scott Meyers Warned Us About

2018-05-27 Thread 12345swordy via Digitalmars-d
On Sunday, 27 May 2018 at 18:55:41 UTC, Mike Franklin wrote: On Sunday, 27 May 2018 at 16:06:21 UTC, 12345swordy wrote: You are replacing runtime typeinfo with compiletime templates. Unless you can guarantee that the type information won't change during runtime, you are going to have a hard

Re: D's Destructors are What Scott Meyers Warned Us About

2018-05-27 Thread Mike Franklin via Digitalmars-d
On Sunday, 27 May 2018 at 16:06:21 UTC, 12345swordy wrote: You are replacing runtime typeinfo with compiletime templates. Unless you can guarantee that the type information won't change during runtime, you are going to have a hard time. Read this thread for context

Re: D's Destructors are What Scott Meyers Warned Us About

2018-05-27 Thread 12345swordy via Digitalmars-d
On Sunday, 27 May 2018 at 09:55:56 UTC, Mike Franklin wrote: On Friday, 25 May 2018 at 23:47:33 UTC, sarn wrote: [...] I'm very much interested in doing something about these functions. __xdtor is just one. There are others at

Re: D's Destructors are What Scott Meyers Warned Us About

2018-05-27 Thread Mike Franklin via Digitalmars-d
On Friday, 25 May 2018 at 23:47:33 UTC, sarn wrote: That std.signals code that Steven filed a bug report for is example of why we can't just fix the behaviour, though. If we just fixed __dtor/__xdtor, any code that used std.signals would start having ugly bugs at run time. I think that

Re: D's Destructors are What Scott Meyers Warned Us About

2018-05-27 Thread Mike Franklin via Digitalmars-d
On Wednesday, 23 May 2018 at 19:05:38 UTC, Manu wrote: 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! I had an in-depth discussion with Andrei about this

Re: D's Destructors are What Scott Meyers Warned Us About

2018-05-25 Thread sarn via Digitalmars-d
On Thursday, 24 May 2018 at 12:26:00 UTC, Steven Schveighoffer wrote: I added the bug report here: https://issues.dlang.org/show_bug.cgi?id=18903. I outline exactly how to fix it, if anyone wants an easy PR opportunity. -Steve Thanks for digging into that. On Wednesday, 23 May 2018 at

Re: D's Destructors are What Scott Meyers Warned Us About

2018-05-24 Thread Steven Schveighoffer via Digitalmars-d
On 5/24/18 5:32 AM, Steven Schveighoffer wrote: On 5/23/18 7:11 PM, sarn wrote: Here's an example of what I'm talking about: https://github.com/dlang/phobos/blob/master/std/signals.d#L230 It's running __dtor manually just to run some code that happens to be in the destructor.  It's

Re: D's Destructors are What Scott Meyers Warned Us About

2018-05-24 Thread Steven Schveighoffer via Digitalmars-d
On 5/23/18 7:11 PM, sarn wrote: On Wednesday, 23 May 2018 at 13:12:57 UTC, Steven Schveighoffer wrote: On 5/22/18 9:59 PM, sarn wrote: * Some code uses __dtor as a way to manually run cleanup code on an object that will be used again.  Putting this cleanup code into a normal method will cause

Re: D's Destructors are What Scott Meyers Warned Us About

2018-05-24 Thread Steven Schveighoffer via Digitalmars-d
On 5/23/18 9:38 PM, Mike Franklin wrote: On Wednesday, 23 May 2018 at 13:12:57 UTC, Steven Schveighoffer wrote: Hm.. that should be fixed. I don't see why we can't just do = T.init, we should at least be optimizing to this for small enough structs. The problem I ran into with this is that if

Re: D's Destructors are What Scott Meyers Warned Us About

2018-05-23 Thread Mike Franklin via Digitalmars-d
On Wednesday, 23 May 2018 at 13:12:57 UTC, Steven Schveighoffer wrote: Hm.. that should be fixed. I don't see why we can't just do = T.init, we should at least be optimizing to this for small enough structs. The problem I ran into with this is that if you use T.init directly you end up

Re: D's Destructors are What Scott Meyers Warned Us About

2018-05-23 Thread Manu via Digitalmars-d
On 23 May 2018 at 16:34, Rubn via Digitalmars-d wrote: > On Wednesday, 23 May 2018 at 22:47:21 UTC, sarn wrote: >> >> On Wednesday, 23 May 2018 at 02:13:13 UTC, rikki cattermole wrote: >>> >>> I would consider the current state with classes a bug. >>> So ticket

Re: D's Destructors are What Scott Meyers Warned Us About

2018-05-23 Thread Rubn via Digitalmars-d
On Wednesday, 23 May 2018 at 22:47:21 UTC, sarn wrote: On Wednesday, 23 May 2018 at 02:13:13 UTC, rikki cattermole wrote: I would consider the current state with classes a bug. So ticket please, it should not require a DIP to change (although Walter may disagree). Unfortunately, the way

Re: D's Destructors are What Scott Meyers Warned Us About

2018-05-23 Thread sarn via Digitalmars-d
On Wednesday, 23 May 2018 at 15:43:31 UTC, Steven Schveighoffer wrote: Coincidentally, this JUST changed due to a different reason: https://github.com/dlang/druntime/pull/2178 Please file an enhancement request. I still think it could be better, so I added a further issue:

Re: D's Destructors are What Scott Meyers Warned Us About

2018-05-23 Thread Manu via Digitalmars-d
On 23 May 2018 at 15:47, sarn via Digitalmars-d wrote: > On Wednesday, 23 May 2018 at 02:13:13 UTC, rikki cattermole wrote: >> >> I would consider the current state with classes a bug. >> So ticket please, it should not require a DIP to change (although Walter >> may

Re: D's Destructors are What Scott Meyers Warned Us About

2018-05-23 Thread sarn via Digitalmars-d
On Wednesday, 23 May 2018 at 13:12:57 UTC, Steven Schveighoffer wrote: On 5/22/18 9:59 PM, sarn wrote: * Some code uses __dtor as a way to manually run cleanup code on an object that will be used again.  Putting this cleanup code into a normal method will cause fewer headaches. Using __dtor

Re: D's Destructors are What Scott Meyers Warned Us About

2018-05-23 Thread sarn via Digitalmars-d
On Wednesday, 23 May 2018 at 02:13:13 UTC, rikki cattermole wrote: I would consider the current state with classes a bug. So ticket please, it should not require a DIP to change (although Walter may disagree). Unfortunately, the way __dtor and __xdtor work for classes can't be changed

Re: D's Destructors are What Scott Meyers Warned Us About

2018-05-23 Thread sarn via Digitalmars-d
On Wednesday, 23 May 2018 at 19:28:28 UTC, Paul Backus wrote: On Wednesday, 23 May 2018 at 01:59:50 UTC, sarn wrote: The one other usage of these low-level destructor facilities is checking if a type is a plain old data struct. This is an important special case for some code, but everyone

Re: D's Destructors are What Scott Meyers Warned Us About

2018-05-23 Thread Paul Backus via Digitalmars-d
On Wednesday, 23 May 2018 at 01:59:50 UTC, sarn wrote: The one other usage of these low-level destructor facilities is checking if a type is a plain old data struct. This is an important special case for some code, but everyone seems to do the check a different way. Maybe a special isPod

Re: D's Destructors are What Scott Meyers Warned Us About

2018-05-23 Thread Manu via Digitalmars-d
On 23 May 2018 at 10:59, Steven Schveighoffer via Digitalmars-d wrote: > On 5/23/18 1:41 PM, Manu wrote: >> >> On 23 May 2018 at 05:38, Steven Schveighoffer via Digitalmars-d >> wrote: >>> >>> On 5/22/18 10:15 PM, Manu wrote:

Re: D's Destructors are What Scott Meyers Warned Us About

2018-05-23 Thread 12345swordy via Digitalmars-d
On Wednesday, 23 May 2018 at 18:11:45 UTC, Jonathan M Davis wrote: On Wednesday, May 23, 2018 18:04:28 12345swordy via Digitalmars-d wrote: On Wednesday, 23 May 2018 at 17:47:12 UTC, Jonathan M Davis wrote: > On Wednesday, May 23, 2018 17:29:11 12345swordy via > > Digitalmars-d wrote: >> [...]

Re: D's Destructors are What Scott Meyers Warned Us About

2018-05-23 Thread Jonathan M Davis via Digitalmars-d
On Wednesday, May 23, 2018 18:04:28 12345swordy via Digitalmars-d wrote: > On Wednesday, 23 May 2018 at 17:47:12 UTC, Jonathan M Davis wrote: > > On Wednesday, May 23, 2018 17:29:11 12345swordy via > > > > Digitalmars-d wrote: > >> On Wednesday, 23 May 2018 at 15:43:31 UTC, Steven Schveighoffer >

Re: D's Destructors are What Scott Meyers Warned Us About

2018-05-23 Thread Steven Schveighoffer via Digitalmars-d
On 5/23/18 1:41 PM, Manu wrote: Is everything in object.d globally available? You don't have to import `destroy()` right? Oh, didn't answer this, yes object.d is always imported. -Steve

Re: D's Destructors are What Scott Meyers Warned Us About

2018-05-23 Thread 12345swordy via Digitalmars-d
On Wednesday, 23 May 2018 at 17:47:12 UTC, Jonathan M Davis wrote: On Wednesday, May 23, 2018 17:29:11 12345swordy via Digitalmars-d wrote: On Wednesday, 23 May 2018 at 15:43:31 UTC, Steven Schveighoffer wrote: > On 5/23/18 9:12 AM, Steven Schveighoffer wrote: >> [...] > > Coincidentally, this

Re: D's Destructors are What Scott Meyers Warned Us About

2018-05-23 Thread Steven Schveighoffer via Digitalmars-d
On 5/23/18 1:41 PM, Manu wrote: On 23 May 2018 at 05:38, Steven Schveighoffer via Digitalmars-d 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();

Re: D's Destructors are What Scott Meyers Warned Us About

2018-05-23 Thread Jonathan M Davis via Digitalmars-d
On Wednesday, May 23, 2018 17:29:11 12345swordy via Digitalmars-d wrote: > On Wednesday, 23 May 2018 at 15:43:31 UTC, Steven Schveighoffer > > wrote: > > On 5/23/18 9:12 AM, Steven Schveighoffer wrote: > >> On 5/22/18 9:59 PM, sarn wrote: > >>> (Unfortunately destroy() currently isn't

Re: D's Destructors are What Scott Meyers Warned Us About

2018-05-23 Thread Manu via Digitalmars-d
On 23 May 2018 at 05:38, Steven Schveighoffer via Digitalmars-d 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

Re: D's Destructors are What Scott Meyers Warned Us About

2018-05-23 Thread 12345swordy via Digitalmars-d
On Wednesday, 23 May 2018 at 15:43:31 UTC, Steven Schveighoffer wrote: On 5/23/18 9:12 AM, Steven Schveighoffer wrote: On 5/22/18 9:59 PM, sarn wrote: (Unfortunately destroy() currently isn't zero-overhead for plain old data structs because it's based on RTTI, but at least it works.) Hm..

Re: D's Destructors are What Scott Meyers Warned Us About

2018-05-23 Thread Steven Schveighoffer via Digitalmars-d
On 5/23/18 9:12 AM, Steven Schveighoffer wrote: On 5/22/18 9:59 PM, sarn wrote: (Unfortunately destroy() currently isn't zero-overhead for plain old data structs because it's based on RTTI, but at least it works.) Hm.. that should be fixed. I don't see why we can't just do = T.init, we

Re: D's Destructors are What Scott Meyers Warned Us About

2018-05-23 Thread 12345swordy via Digitalmars-d
On Wednesday, 23 May 2018 at 03:45:39 UTC, Manu wrote: On 22 May 2018 at 19:39, 12345swordy via Digitalmars-d wrote: On Wednesday, 23 May 2018 at 02:15:25 UTC, Manu wrote: It should recurse the ClassInfo calling the dtors there to perform a full virtual

Re: D's Destructors are What Scott Meyers Warned Us About

2018-05-23 Thread Steven Schveighoffer via Digitalmars-d
On 5/22/18 9:59 PM, sarn wrote: (I'm referring to Scott's 2014 DConf talk: https://www.youtube.com/watch?v=KAWA1DuvCnQ) I was actually preparing a DIP about this when Manu posted to the forums about his own related problems with C++ interop. I traced a bug in some of my D code to my own

Re: D's Destructors are What Scott Meyers Warned Us About

2018-05-23 Thread Steven Schveighoffer via Digitalmars-d
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() ? -Steve

Re: D's Destructors are What Scott Meyers Warned Us About

2018-05-23 Thread Guillaume Piolat via Digitalmars-d
On Wednesday, 23 May 2018 at 01:59:50 UTC, sarn wrote: I'm starting this thread to talk about ways to make things better, but first the bad news. Let's use this idiomatic code as an example of typical bugs: Keep up the good work of explaining surprising things! Someone has to do Scott's

Re: D's Destructors are What Scott Meyers Warned Us About

2018-05-22 Thread 12345swordy via Digitalmars-d
On Wednesday, 23 May 2018 at 03:45:39 UTC, Manu wrote: ... what? Konw it off with the sex talk here.

Re: D's Destructors are What Scott Meyers Warned Us About

2018-05-22 Thread Manu via Digitalmars-d
On 22 May 2018 at 19:39, 12345swordy via Digitalmars-d wrote: > On Wednesday, 23 May 2018 at 02:15:25 UTC, Manu wrote: >> >> It should recurse the ClassInfo calling the dtors there to perform a >> full virtual destruction. > > > Why? That seems restrictive as there is

Re: D's Destructors are What Scott Meyers Warned Us About

2018-05-22 Thread 12345swordy via Digitalmars-d
On Wednesday, 23 May 2018 at 02:15:25 UTC, Manu wrote: It should recurse the ClassInfo calling the dtors there to perform a full virtual destruction. Why? That seems restrictive as there is possibility that the parent class have an empty destruction with no attributes which your suggestion

Re: D's Destructors are What Scott Meyers Warned Us About

2018-05-22 Thread Manu via Digitalmars-d
On 22 May 2018 at 18:59, sarn via Digitalmars-d wrote: > (I'm referring to Scott's 2014 DConf talk: > https://www.youtube.com/watch?v=KAWA1DuvCnQ) > > I was actually preparing a DIP about this when Manu posted to the forums > about his own related problems with C++

Re: D's Destructors are What Scott Meyers Warned Us About

2018-05-22 Thread rikki cattermole via Digitalmars-d
On 23/05/2018 1:59 PM, sarn wrote: (I'm referring to Scott's 2014 DConf talk: https://www.youtube.com/watch?v=KAWA1DuvCnQ) I was actually preparing a DIP about this when Manu posted to the forums about his own related problems with C++ interop. I traced a bug in some of my D code to my own

D's Destructors are What Scott Meyers Warned Us About

2018-05-22 Thread sarn via Digitalmars-d
(I'm referring to Scott's 2014 DConf talk: https://www.youtube.com/watch?v=KAWA1DuvCnQ) I was actually preparing a DIP about this when Manu posted to the forums about his own related problems with C++ interop. I traced a bug in some of my D code to my own misunderstanding of how D's