digitalmars.D - clear() and UFCS
- =?ISO-8859-1?Q?Alex_R=F8nne_Petersen?= (16/16) May 25 2012 So I was writing a container class and in some test code, I called
- Dmitry Olshansky (6/18) May 25 2012 No, there are thousands like you. Let's call clear "nuke", breaking TDPL...
- Andrei Alexandrescu (3/23) May 25 2012 Since this is a recurring issue we should probably change the name.
- deadalnix (4/29) May 25 2012 It has already been suggested, but finalize is something that is
- deadalnix (2/14) May 25 2012 Why is UFCS involved here ?
- =?ISO-8859-1?Q?Alex_R=F8nne_Petersen?= (7/25) May 25 2012 Since the clear method didn't exist on the type, the call was mapped to
- deadalnix (4/26) May 25 2012 OK, I get it ! Weird side effect :D
- =?ISO-8859-1?Q?Alex_R=F8nne_Petersen?= (6/35) May 25 2012 I think clear() is basically entirely undocumented still.
-
Steven Schveighoffer
(11/45)
May 25 2012
On Fri, 25 May 2012 10:52:15 -0400, Alex R=C3=B8nne Petersen
- =?UTF-8?B?QWxleCBSw7hubmUgUGV0ZXJzZW4=?= (6/45) May 25 2012 We actually have tons of documentation that still encourages using delet...
- =?UTF-8?B?QWxleCBSw7hubmUgUGV0ZXJzZW4=?= (6/45) May 25 2012 Before we do, we should deprecate clear and rename it to finalize, thoug...
-
Steven Schveighoffer
(7/12)
May 25 2012
On Fri, 25 May 2012 11:03:33 -0400, Alex R=C3=B8nne Petersen
- =?UTF-8?B?QWxleCBSw7hubmUgUGV0ZXJzZW4=?= (6/18) May 25 2012 But it calls rt_finalize...?
-
Steven Schveighoffer
(15/33)
May 25 2012
On Fri, 25 May 2012 11:28:07 -0400, Alex R=C3=B8nne Petersen
- Steven Schveighoffer (9/39) May 25 2012 us.org> =
- Mirko Pilger (1/3) May 25 2012 what about "invalidate"?
- Andrei Alexandrescu (4/7) May 25 2012 Whatever it is, I should say I'll be very strongly opposed to any
- Francisco Almeida (6/15) May 26 2012 I vote for destroy().
- =?UTF-8?B?QWxleCBSw7hubmUgUGV0ZXJzZW4=?= (7/22) May 26 2012 It doesn't actually matter. It wouldn't be ambiguous. UFCS prefers the
- David Nadlinger (6/16) May 26 2012 It wouldn't break existing types, yes, but would probably cause
- sclytrack (7/49) May 25 2012 blank, destroy, trash, dump, zero, bleach, cleanup,
- Brad Anderson (2/63) May 25 2012 I'm partial to defenestrate().
- John Chapman (3/14) May 25 2012 One for the Doctor Who fans among us:
- Mehrdad (2/16) May 25 2012 or we could just, uh, bring back delete...
- Jonathan M Davis (7/25) May 25 2012 clear and delete are very different things. It was definitely decided th...
- Mehrdad (2/2) May 25 2012 Would you mind explaining the difference between clear(), delete,
- Jonathan M Davis (38/40) May 25 2012 clear destroys the object (by calling its finalizer or destructor) and t...
- Mehrdad (6/6) May 25 2012 Okay, thanks for the explanation.
- Jonathan M Davis (12/19) May 25 2012 Yes, though it calls rt_finalize on classes rather than dtor directly, s...
- Mehrdad (3/7) May 25 2012 Ahh, that was what confused me, thanks... I thought you were
- Mehrdad (1/1) May 25 2012 Why not just call it 'destroy()'?
- jerro (2/3) May 25 2012 +1
- sclytrack (3/6) May 25 2012 +1
- RivenTheMage (2/8) May 26 2012 +1
- Era Scarecrow (8/17) May 26 2012 +1
- Jacob Carlborg (4/10) May 26 2012 Why can't "delete" do what "clear" does. Backwards compatibility?
- Michel Fortin (16/27) May 26 2012 That'd be my preferred solution too. I think it makes a lot of sense.
- Jonathan M Davis (20/30) May 26 2012 I would think that that would be a bad idea, because it wouldn't be doin...
- Andrei Alexandrescu (3/21) May 25 2012 delete also deallocates.
- Dmitry Olshansky (4/10) May 25 2012 I like wipe though obliterate is so much clearer ... :)
- Simen Kjaeraas (4/15) May 29 2012 I also love obliterate. And annihilate. But I would be more than happy w...
- Joshua Niehus (1/6) May 25 2012 disembowel?
- Ary Manzana (7/8) May 25 2012 In Java it's finalize:
- Steven Schveighoffer (8/16) May 30 2012 No, this is the GC finalizer. This is equivalent to D's class destructo...
- =?UTF-8?B?QWxleCBSw7hubmUgUGV0ZXJzZW4=?= (9/40) May 25 2012 But if clear() *does* run the finalizer *now*, then finalize would be a
-
Steven Schveighoffer
(27/69)
May 25 2012
On Fri, 25 May 2012 11:42:57 -0400, Alex R=C3=B8nne Petersen
- =?UTF-8?B?QWxleCBSw7hubmUgUGV0ZXJzZW4=?= (6/73) May 25 2012 Sounds good to me.
- =?ISO-8859-1?Q?S=F6nke_Ludwig?= (6/18) May 25 2012 I completely agree! Had the same situation before...
- Artur Skawina (3/25) May 25 2012 @method ?
- Jonathan M Davis (4/19) May 29 2012 an
- =?UTF-8?B?QWxleCBSw7hubmUgUGV0ZXJzZW4=?= (6/23) May 30 2012 Thanks!
So I was writing a container class and in some test code, I called container.clear(). Reasonable enough, right? Hell, it even compiled! Turns out, my program completely broke at runtime. Apparently, I'd forgotten to implement clear() on my container class, and *object.clear() was being called instead*. I don't blame UFCS for this. It just happened to be the reason this compiled at all. But, what I do think is: clear is the *ABSOLUTELY MOST HORRIBLE NAME EVER* for a function that actually finalizes and zeroes an object. Did it not seem obvious to call it, I don't know, *finalize*? And even ignoring the naming, having a symbol called clear in the 'global' namespace is absolute insanity. Am I the only person with this opinion? -- Alex Rønne Petersen alex lycus.org http://lycus.org
May 25 2012
On 25.05.2012 17:04, Alex Rønne Petersen wrote:So I was writing a container class and in some test code, I called container.clear(). Reasonable enough, right? Hell, it even compiled! Turns out, my program completely broke at runtime. Apparently, I'd forgotten to implement clear() on my container class, and *object.clear() was being called instead*. I don't blame UFCS for this. It just happened to be the reason this compiled at all. But, what I do think is: clear is the *ABSOLUTELY MOST HORRIBLE NAME EVER* for a function that actually finalizes and zeroes an object. Did it not seem obvious to call it, I don't know, *finalize*? And even ignoring the naming, having a symbol called clear in the 'global' namespace is absolute insanity. Am I the only person with this opinion?No, there are thousands like you. Let's call clear "nuke", breaking TDPL and saving the day. :) P.S. Obviously first clear goes through normal deprecation cycle. -- Dmitry Olshansky
May 25 2012
On 5/25/12 8:06 AM, Dmitry Olshansky wrote:On 25.05.2012 17:04, Alex Rønne Petersen wrote:Since this is a recurring issue we should probably change the name. AndreiSo I was writing a container class and in some test code, I called container.clear(). Reasonable enough, right? Hell, it even compiled! Turns out, my program completely broke at runtime. Apparently, I'd forgotten to implement clear() on my container class, and *object.clear() was being called instead*. I don't blame UFCS for this. It just happened to be the reason this compiled at all. But, what I do think is: clear is the *ABSOLUTELY MOST HORRIBLE NAME EVER* for a function that actually finalizes and zeroes an object. Did it not seem obvious to call it, I don't know, *finalize*? And even ignoring the naming, having a symbol called clear in the 'global' namespace is absolute insanity. Am I the only person with this opinion?No, there are thousands like you. Let's call clear "nuke", breaking TDPL and saving the day. :) P.S. Obviously first clear goes through normal deprecation cycle.
May 25 2012
Le 25/05/2012 17:00, Andrei Alexandrescu a écrit :On 5/25/12 8:06 AM, Dmitry Olshansky wrote:It has already been suggested, but finalize is something that is explicit, and it is already used in other languages. We should go that way IMO.On 25.05.2012 17:04, Alex Rønne Petersen wrote:Since this is a recurring issue we should probably change the name. AndreiSo I was writing a container class and in some test code, I called container.clear(). Reasonable enough, right? Hell, it even compiled! Turns out, my program completely broke at runtime. Apparently, I'd forgotten to implement clear() on my container class, and *object.clear() was being called instead*. I don't blame UFCS for this. It just happened to be the reason this compiled at all. But, what I do think is: clear is the *ABSOLUTELY MOST HORRIBLE NAME EVER* for a function that actually finalizes and zeroes an object. Did it not seem obvious to call it, I don't know, *finalize*? And even ignoring the naming, having a symbol called clear in the 'global' namespace is absolute insanity. Am I the only person with this opinion?No, there are thousands like you. Let's call clear "nuke", breaking TDPL and saving the day. :) P.S. Obviously first clear goes through normal deprecation cycle.
May 25 2012
Le 25/05/2012 15:04, Alex Rønne Petersen a écrit :So I was writing a container class and in some test code, I called container.clear(). Reasonable enough, right? Hell, it even compiled! Turns out, my program completely broke at runtime. Apparently, I'd forgotten to implement clear() on my container class, and *object.clear() was being called instead*. I don't blame UFCS for this. It just happened to be the reason this compiled at all. But, what I do think is: clear is the *ABSOLUTELY MOST HORRIBLE NAME EVER* for a function that actually finalizes and zeroes an object. Did it not seem obvious to call it, I don't know, *finalize*? And even ignoring the naming, having a symbol called clear in the 'global' namespace is absolute insanity. Am I the only person with this opinion?Why is UFCS involved here ?
May 25 2012
On 25-05-2012 15:17, deadalnix wrote:Le 25/05/2012 15:04, Alex Rønne Petersen a écrit :Since the clear method didn't exist on the type, the call was mapped to the clear function in the global scope. This is UFCS. -- Alex Rønne Petersen alex lycus.org http://lycus.orgSo I was writing a container class and in some test code, I called container.clear(). Reasonable enough, right? Hell, it even compiled! Turns out, my program completely broke at runtime. Apparently, I'd forgotten to implement clear() on my container class, and *object.clear() was being called instead*. I don't blame UFCS for this. It just happened to be the reason this compiled at all. But, what I do think is: clear is the *ABSOLUTELY MOST HORRIBLE NAME EVER* for a function that actually finalizes and zeroes an object. Did it not seem obvious to call it, I don't know, *finalize*? And even ignoring the naming, having a symbol called clear in the 'global' namespace is absolute insanity. Am I the only person with this opinion?Why is UFCS involved here ?
May 25 2012
Le 25/05/2012 15:21, Alex Rønne Petersen a écrit :On 25-05-2012 15:17, deadalnix wrote:OK, I get it ! Weird side effect :D BTW, where is the documentation about clear and emplace ? I can't find it on dlang.org .Le 25/05/2012 15:04, Alex Rønne Petersen a écrit :Since the clear method didn't exist on the type, the call was mapped to the clear function in the global scope. This is UFCS.So I was writing a container class and in some test code, I called container.clear(). Reasonable enough, right? Hell, it even compiled! Turns out, my program completely broke at runtime. Apparently, I'd forgotten to implement clear() on my container class, and *object.clear() was being called instead*. I don't blame UFCS for this. It just happened to be the reason this compiled at all. But, what I do think is: clear is the *ABSOLUTELY MOST HORRIBLE NAME EVER* for a function that actually finalizes and zeroes an object. Did it not seem obvious to call it, I don't know, *finalize*? And even ignoring the naming, having a symbol called clear in the 'global' namespace is absolute insanity. Am I the only person with this opinion?Why is UFCS involved here ?
May 25 2012
On 25-05-2012 16:50, deadalnix wrote:Le 25/05/2012 15:21, Alex Rønne Petersen a écrit :I think clear() is basically entirely undocumented still. -- Alex Rønne Petersen alex lycus.org http://lycus.orgOn 25-05-2012 15:17, deadalnix wrote:OK, I get it ! Weird side effect :D BTW, where is the documentation about clear and emplace ? I can't find it on dlang.org .Le 25/05/2012 15:04, Alex Rønne Petersen a écrit :Since the clear method didn't exist on the type, the call was mapped to the clear function in the global scope. This is UFCS.So I was writing a container class and in some test code, I called container.clear(). Reasonable enough, right? Hell, it even compiled! Turns out, my program completely broke at runtime. Apparently, I'd forgotten to implement clear() on my container class, and *object.clear() was being called instead*. I don't blame UFCS for this. It just happened to be the reason this compiled at all. But, what I do think is: clear is the *ABSOLUTELY MOST HORRIBLE NAME EVER* for a function that actually finalizes and zeroes an object. Did it not seem obvious to call it, I don't know, *finalize*? And even ignoring the naming, having a symbol called clear in the 'global' namespace is absolute insanity. Am I the only person with this opinion?Why is UFCS involved here ?
May 25 2012
On Fri, 25 May 2012 10:52:15 -0400, Alex R=C3=B8nne Petersen <alex lycus= .org> = wrote:On 25-05-2012 16:50, deadalnix wrote:Le 25/05/2012 15:21, Alex R=C3=B8nne Petersen a =C3=A9crit :On 25-05-2012 15:17, deadalnix wrote:Le 25/05/2012 15:04, Alex R=C3=B8nne Petersen a =C3=A9crit :So I was writing a container class and in some test code, I called=d!container.clear(). Reasonable enough, right? Hell, it even compile=Turns out, my program completely broke at runtime. Apparently, I'd=sforgotten to implement clear() on my container class, and *object.clear() was being called instead*. I don't blame UFCS for this. It just happened to be the reason thi==compiled at all. But, what I do think is: clear is the *ABSOLUTELY=e*?MOST HORRIBLE NAME EVER* for a function that actually finalizes and zeroes an object. Did it not seem obvious to call it, I don't know, *finaliz=toSince the clear method didn't exist on the type, the call was mapped=And even ignoring the naming, having a symbol called clear in the 'global' namespace is absolute insanity. Am I the only person with this opinion?Why is UFCS involved here ?dthe clear function in the global scope. This is UFCS.OK, I get it ! Weird side effect :D BTW, where is the documentation about clear and emplace ? I can't fin=Wow, you're right, it's not documented. That should be fixed! -Steveit on dlang.org .I think clear() is basically entirely undocumented still.
May 25 2012
On 25-05-2012 16:56, Steven Schveighoffer wrote:On Fri, 25 May 2012 10:52:15 -0400, Alex Rønne Petersen <alex lycus..org> wrote:We actually have tons of documentation that still encourages using delete... -- Alex Rønne Petersen alex lycus.org http://lycus.orgOn 25-05-2012 16:50, deadalnix wrote:Wow, you're right, it's not documented. That should be fixed! -SteveLe 25/05/2012 15:21, Alex Rønne Petersen a écrit :I think clear() is basically entirely undocumented still.On 25-05-2012 15:17, deadalnix wrote:OK, I get it ! Weird side effect :D BTW, where is the documentation about clear and emplace ? I can't find it on dlang.org .Le 25/05/2012 15:04, Alex Rønne Petersen a écrit :Since the clear method didn't exist on the type, the call was mapped to the clear function in the global scope. This is UFCS.So I was writing a container class and in some test code, I called container.clear(). Reasonable enough, right? Hell, it even compiled! Turns out, my program completely broke at runtime. Apparently, I'd forgotten to implement clear() on my container class, and *object.clear() was being called instead*. I don't blame UFCS for this. It just happened to be the reason this compiled at all. But, what I do think is: clear is the *ABSOLUTELY MOST HORRIBLE NAME EVER* for a function that actually finalizes and zeroes an object. Did it not seem obvious to call it, I don't know, *finalize*? And even ignoring the naming, having a symbol called clear in the 'global' namespace is absolute insanity. Am I the only person with this opinion?Why is UFCS involved here ?
May 25 2012
On 25-05-2012 16:56, Steven Schveighoffer wrote:On Fri, 25 May 2012 10:52:15 -0400, Alex Rønne Petersen <alex lycus..org> wrote:Before we do, we should deprecate clear and rename it to finalize, though. -- Alex Rønne Petersen alex lycus.org http://lycus.orgOn 25-05-2012 16:50, deadalnix wrote:Wow, you're right, it's not documented. That should be fixed! -SteveLe 25/05/2012 15:21, Alex Rønne Petersen a écrit :I think clear() is basically entirely undocumented still.On 25-05-2012 15:17, deadalnix wrote:OK, I get it ! Weird side effect :D BTW, where is the documentation about clear and emplace ? I can't find it on dlang.org .Le 25/05/2012 15:04, Alex Rønne Petersen a écrit :Since the clear method didn't exist on the type, the call was mapped to the clear function in the global scope. This is UFCS.So I was writing a container class and in some test code, I called container.clear(). Reasonable enough, right? Hell, it even compiled! Turns out, my program completely broke at runtime. Apparently, I'd forgotten to implement clear() on my container class, and *object.clear() was being called instead*. I don't blame UFCS for this. It just happened to be the reason this compiled at all. But, what I do think is: clear is the *ABSOLUTELY MOST HORRIBLE NAME EVER* for a function that actually finalizes and zeroes an object. Did it not seem obvious to call it, I don't know, *finalize*? And even ignoring the naming, having a symbol called clear in the 'global' namespace is absolute insanity. Am I the only person with this opinion?Why is UFCS involved here ?
May 25 2012
On Fri, 25 May 2012 11:03:33 -0400, Alex R=C3=B8nne Petersen <alex lycus= .org> = wrote:On 25-05-2012 16:56, Steven Schveighoffer wrote:Wow, you're right, it's not documented. That should be fixed!Before we do, we should deprecate clear and rename it to finalize, =though.I don't like finalize because it's not a finalizer. I think we should mimic other languages that have a finalizer and a = deterministic dispose function. -Steve
May 25 2012
On 25-05-2012 17:23, Steven Schveighoffer wrote:On Fri, 25 May 2012 11:03:33 -0400, Alex Rønne Petersen <alex lycus..org> wrote:But it calls rt_finalize...? -- Alex Rønne Petersen alex lycus.org http://lycus.orgOn 25-05-2012 16:56, Steven Schveighoffer wrote:I don't like finalize because it's not a finalizer. I think we should mimic other languages that have a finalizer and a deterministic dispose function. -SteveWow, you're right, it's not documented. That should be fixed!Before we do, we should deprecate clear and rename it to finalize, though.
May 25 2012
On Fri, 25 May 2012 11:28:07 -0400, Alex R=C3=B8nne Petersen <alex lycus= .org> = wrote:On 25-05-2012 17:23, Steven Schveighoffer wrote:Yeah, because non-deterministic destruction is part of deterministic = destruction. finalize -> destroy non-gc resources dispose -> 1. do deterministic destruction involving possible GC resourc= es = 2. call finalize. e.g. a buffered file: finalize -> close the file handle dispose -> flush the GC allocated buffer into the handle, then close the= = handle -SteveOn Fri, 25 May 2012 11:03:33 -0400, Alex R=C3=B8nne Petersen <alex lycus..org> wrote:But it calls rt_finalize...?On 25-05-2012 16:56, Steven Schveighoffer wrote:I don't like finalize because it's not a finalizer. I think we should mimic other languages that have a finalizer and a deterministic dispose function. -SteveWow, you're right, it's not documented. That should be fixed!Before we do, we should deprecate clear and rename it to finalize, though.
May 25 2012
On Fri, 25 May 2012 11:37:52 -0400, Steven Schveighoffer = <schveiguy yahoo.com> wrote:On Fri, 25 May 2012 11:28:07 -0400, Alex R=C3=B8nne Petersen <alex lyc=us.org> =wrote:On 25-05-2012 17:23, Steven Schveighoffer wrote:Yeah, because non-deterministic destruction is part of deterministic =On Fri, 25 May 2012 11:03:33 -0400, Alex R=C3=B8nne Petersen <alex lycus..org> wrote:But it calls rt_finalize...?On 25-05-2012 16:56, Steven Schveighoffer wrote:I don't like finalize because it's not a finalizer. I think we should mimic other languages that have a finalizer and a deterministic dispose function. -SteveWow, you're right, it's not documented. That should be fixed!Before we do, we should deprecate clear and rename it to finalize, though.destruction. finalize -> destroy non-gc resources dispose -> 1. do deterministic destruction involving possible GC =resources 2. call finalize. e.g. a buffered file: finalize -> close the file handle dispose -> flush the GC allocated buffer into the handle, then close t=he =handleI take it back, dispose is no good. That should be the name of the = deterministic destructor in the object. Now I don't have a good name. Finalize isn't right, and neither is = dispose... -Steve
May 25 2012
Now I don't have a good name. Finalize isn't right, and neither is dispose...what about "invalidate"?
May 25 2012
On 5/25/12 12:37 PM, Mirko Pilger wrote:Whatever it is, I should say I'll be very strongly opposed to any proposal if it is about as controversial as "clear". AndreiNow I don't have a good name. Finalize isn't right, and neither is dispose...what about "invalidate"?
May 25 2012
On Friday, 25 May 2012 at 18:22:08 UTC, Andrei Alexandrescu wrote:On 5/25/12 12:37 PM, Mirko Pilger wrote:I vote for destroy(). It seems to be a popular choice, and it isn't ambiguous in any way. Are there any classes/structs using destroy() methods in Phobos? FranciscoWhatever it is, I should say I'll be very strongly opposed to any proposal if it is about as controversial as "clear". AndreiNow I don't have a good name. Finalize isn't right, and neither is dispose...what about "invalidate"?
May 26 2012
On 26-05-2012 10:48, Francisco Almeida wrote:On Friday, 25 May 2012 at 18:22:08 UTC, Andrei Alexandrescu wrote:It doesn't actually matter. It wouldn't be ambiguous. UFCS prefers the method on a class/struct over a free function. -- Alex Rønne Petersen alex lycus.org http://lycus.orgOn 5/25/12 12:37 PM, Mirko Pilger wrote:I vote for destroy(). It seems to be a popular choice, and it isn't ambiguous in any way. Are there any classes/structs using destroy() methods in Phobos? FranciscoWhatever it is, I should say I'll be very strongly opposed to any proposal if it is about as controversial as "clear". AndreiNow I don't have a good name. Finalize isn't right, and neither is dispose...what about "invalidate"?
May 26 2012
On Saturday, 26 May 2012 at 08:52:06 UTC, Alex Rønne Petersen wrote:On 26-05-2012 10:48, Francisco Almeida wrote:It wouldn't break existing types, yes, but would probably cause confusion similar to clear() right now if the name was already in (widespread) use. DavidI vote for destroy(). It seems to be a popular choice, and it isn't ambiguous in any way. Are there any classes/structs using destroy() methods in Phobos? FranciscoIt doesn't actually matter. It wouldn't be ambiguous. UFCS prefers the method on a class/struct over a free function.
May 26 2012
On 05/25/2012 05:42 PM, Steven Schveighoffer wrote:On Fri, 25 May 2012 11:37:52 -0400, Steven Schveighoffer <schveiguy yahoo.com> wrote:blank, destroy, trash, dump, zero, bleach, cleanup, sanitize, burn, nuke, eject, jetisson, discard, landfill, waste, litter, debris, recycle, obliterate, annihilate, eradicate, expunge, finish, ravage, wipe, zap, abolish, decimate, demolish, massacre, murder, ruin, slaughter, quash, scrub, splatOn Fri, 25 May 2012 11:28:07 -0400, Alex Rønne Petersen <alex lycus.org> wrote:I take it back, dispose is no good. That should be the name of the deterministic destructor in the object. Now I don't have a good name. Finalize isn't right, and neither is dispose... -SteveOn 25-05-2012 17:23, Steven Schveighoffer wrote:Yeah, because non-deterministic destruction is part of deterministic destruction. finalize -> destroy non-gc resources dispose -> 1. do deterministic destruction involving possible GC resources 2. call finalize. e.g. a buffered file: finalize -> close the file handle dispose -> flush the GC allocated buffer into the handle, then close the handleOn Fri, 25 May 2012 11:03:33 -0400, Alex Rønne Petersen <alex lycus..org> wrote:But it calls rt_finalize...?On 25-05-2012 16:56, Steven Schveighoffer wrote:I don't like finalize because it's not a finalizer. I think we should mimic other languages that have a finalizer and a deterministic dispose function. -SteveWow, you're right, it's not documented. That should be fixed!Before we do, we should deprecate clear and rename it to finalize, though.
May 25 2012
On Fri, May 25, 2012 at 1:34 PM, sclytrack <sclytrack iq87.fr> wrote:On 05/25/2012 05:42 PM, Steven Schveighoffer wrote:I'm partial to defenestrate().On Fri, 25 May 2012 11:37:52 -0400, Steven Schveighoffer <schveiguy yahoo.com> wrote: On Fri, 25 May 2012 11:28:07 -0400, Alex R=F8nne Petersenblank, destroy, trash, dump, zero, bleach, cleanup, sanitize, burn, nuke, eject, jetisson, discard, landfill, waste, litter, debris, recycle, obliterate, annihilate, eradicate, expunge, finish, ravage, wipe, zap, abolish, decimate, demolish, massacre, murder, ruin, slaughter, quash, scrub, splat<alex lycus.org> wrote: On 25-05-2012 17:23, Steven Schveighoffer wrote:I take it back, dispose is no good. That should be the name of the deterministic destructor in the object. Now I don't have a good name. Finalize isn't right, and neither is dispose... -SteveYeah, because non-deterministic destruction is part of deterministic destruction. finalize -> destroy non-gc resources dispose -> 1. do deterministic destruction involving possible GC resources 2. call finalize. e.g. a buffered file: finalize -> close the file handle dispose -> flush the GC allocated buffer into the handle, then close the handleOn Fri, 25 May 2012 11:03:33 -0400, Alex R=F8nne Petersen <alex lycus..org> wrote: On 25-05-2012 16:56, Steven Schveighoffer wrote:But it calls rt_finalize...?I don't like finalize because it's not a finalizer. I think we should mimic other languages that have a finalizer and a deterministic dispose function. -SteveWow, you're right, it's not documented. That should be fixed!Before we do, we should deprecate clear and rename it to finalize, though.
May 25 2012
On Friday, 25 May 2012 at 20:16:32 UTC, Brad Anderson wrote:On Fri, May 25, 2012 at 1:34 PM, sclytrack <sclytrack iq87.fr>One for the Doctor Who fans among us: exterminate().blank, destroy, trash, dump, zero, bleach, cleanup, sanitize, burn, nuke, eject, jetisson, discard, landfill, waste, litter, debris, recycle, obliterate, annihilate, eradicate, expunge, finish, ravage, wipe, zap, abolish, decimate, demolish, massacre, murder, ruin, slaughter, quash, scrub, splatI'm partial to defenestrate().
May 25 2012
On Friday, 25 May 2012 at 20:41:10 UTC, John Chapman wrote:On Friday, 25 May 2012 at 20:16:32 UTC, Brad Anderson wrote:or we could just, uh, bring back delete...On Fri, May 25, 2012 at 1:34 PM, sclytrack <sclytrack iq87.fr>One for the Doctor Who fans among us: exterminate().blank, destroy, trash, dump, zero, bleach, cleanup, sanitize, burn, nuke, eject, jetisson, discard, landfill, waste, litter, debris, recycle, obliterate, annihilate, eradicate, expunge, finish, ravage, wipe, zap, abolish, decimate, demolish, massacre, murder, ruin, slaughter, quash, scrub, splatI'm partial to defenestrate().
May 25 2012
On Saturday, May 26, 2012 02:30:57 Mehrdad wrote:On Friday, 25 May 2012 at 20:41:10 UTC, John Chapman wrote:clear and delete are very different things. It was definitely decided that we'd be better off without delete. It's going for good. Renaming clear to something that doesn't conflict so easily with more benign functions is completely different from bringing back delete. Bringing back delete isn't even on the table at this point. - Jonathan M DavisOn Friday, 25 May 2012 at 20:16:32 UTC, Brad Anderson wrote:or we could just, uh, bring back delete...On Fri, May 25, 2012 at 1:34 PM, sclytrack <sclytrack iq87.fr>One for the Doctor Who fans among us: exterminate().blank, destroy, trash, dump, zero, bleach, cleanup, sanitize, burn, nuke, eject, jetisson, discard, landfill, waste, litter, debris, recycle, obliterate, annihilate, eradicate, expunge, finish, ravage, wipe, zap, abolish, decimate, demolish, massacre, murder, ruin, slaughter, quash, scrub, splatI'm partial to defenestrate().
May 25 2012
Would you mind explaining the difference between clear(), delete, and __dtor/etc? I think it's a little confusing for me.
May 25 2012
On Saturday, May 26, 2012 04:04:51 Mehrdad wrote:Would you mind explaining the difference between clear(), delete, and __dtor/etc? I think it's a little confusing for me.clear destroys the object (by calling its finalizer or destructor) and then in the case of classes, it zeroes out its vtable so that if you accidentally the object after clearing it, it'll blow up rather than getting weird, non- deterministic behavior. In the case of structs, I think that it puts the object in its init state, but I'm not sure. clear does _not_ free the object's memory. It merely destroys the object so that whatever other resources it references can be released (or just unreferenced in the case of GC heap allocated objects that it references). delete does what it does in C++. It destroys the object and then frees the memory. It was decided that having a language construct which freed memory on the GC heap was too dangerous and error-prone and shouldn't be encouraged, so it's being removed. It's still quite possible however, to create a function which destroys and object and then tells the GC to free that object's memory using the stuff in core.memory. __dtor is simply the object's destructor. Calling it calls that function. However, I don't believe that it destroys what the object references (since that would require doing more than simply calling the destructor). As I recall, you have to do something else which is a bit involved to do that. There was a discussion on it recently, but I don't recall the details unfortunately. In the long run, I expect that anyone who really wants to use something akin to delete will likely use custom allocators (e.g. using malloc and free) rather than using the GC heap, possibly with some sort of ref-counting. So, you'd get something like //non-ref-counted auto a = ca.allocate!MyClass(args); ca.deallocate(a); or //ref-counted { auto a = ca.allocate!MyClass(args); } //a has left scope, so its ref-count reach zero, and it was destroyed Obviously we don't have the custom allocator stuff fully ironed out yet though. Andrei has been working on those, but he's been a bit swamped, so who knows when we'll see them. - Jonathan M Davis
May 25 2012
Okay, thanks for the explanation. So basically, clear() just calls __dtor(), and then zeros out the vtable? I don't understand what you mean by "I don't believe that it destroys what the object references"... why should clear() ever destroy anything except the object that it's destroying?
May 25 2012
On Saturday, May 26, 2012 04:34:30 Mehrdad wrote:Okay, thanks for the explanation. So basically, clear() just calls __dtor(), and then zeros out the vtable?Yes, though it calls rt_finalize on classes rather than dtor directly, so that may do some extra stuff beyond strictly calling __dtor and zeroing out the vtable.I don't understand what you mean by "I don't believe that it destroys what the object references"... why should clear() ever destroy anything except the object that it's destroying?Normally when an object is destroyed, all of its member variables' destructors would be called as well (at least for member variables which are structs or arrays of structs - member variables which are classes aren't finalized). But the destructor itself doesn't call all of the member variables' destructors, so calling __dtor doesn't call them. You have to do something else to get the member variables destroyed as well (something with typeid I think, but I don't remember the details). - Jonathan M Davis
May 25 2012
On Saturday, 26 May 2012 at 02:46:57 UTC, Jonathan M Davis wrote:Normally when an object is destroyed, all of its member variables' destructors would be called as well (at least for member variables which are structs or arrays of structs - member variables which are classes aren't finalized)Ahh, that was what confused me, thanks... I thought you were referring to member /Object/s.
May 25 2012
On Saturday, 26 May 2012 at 03:21:31 UTC, Mehrdad wrote:Why not just call it 'destroy()'?+1
May 25 2012
On 05/26/2012 06:58 AM, jerro wrote:On Saturday, 26 May 2012 at 03:21:31 UTC, Mehrdad wrote:+1 And as a bonus all the Delphi dudes will feel right at home.Why not just call it 'destroy()'?+1
May 25 2012
On Saturday, 26 May 2012 at 06:06:08 UTC, sclytrack wrote:On 05/26/2012 06:58 AM, jerro wrote:+1On Saturday, 26 May 2012 at 03:21:31 UTC, Mehrdad wrote:+1Why not just call it 'destroy()'?+1
May 26 2012
On Saturday, 26 May 2012 at 08:38:10 UTC, RivenTheMage wrote:On Saturday, 26 May 2012 at 06:06:08 UTC, sclytrack wrote:+1 I'll agree, destroy has no hidden meanings and is easy to remember. If 'clear' becomes free, it can be used in other things, say a graphics program that clears a editing window. I also liked recycle and zero. Dump should probably not be used, as having used linux dump to me means you'd want to dump the object's data out to the screen or to a file for analysis.On 05/26/2012 06:58 AM, jerro wrote:+1On Saturday, 26 May 2012 at 03:21:31 UTC, Mehrdad wrote:+1Why not just call it 'destroy()'?+1
May 26 2012
On 2012-05-26 03:38, Jonathan M Davis wrote:clear and delete are very different things. It was definitely decided that we'd be better off without delete. It's going for good. Renaming clear to something that doesn't conflict so easily with more benign functions is completely different from bringing back delete. Bringing back delete isn't even on the table at this point. - Jonathan M DavisWhy can't "delete" do what "clear" does. Backwards compatibility? -- /Jacob Carlborg
May 26 2012
On 2012-05-26 12:00:15 +0000, Jacob Carlborg <doob me.com> said:On 2012-05-26 03:38, Jonathan M Davis wrote:That'd be my preferred solution too. I think it makes a lot of sense. Clear does almost the same thing as delete, except that currently delete means memory can be reused immediately, which is not safe. If the only difference is that one is safe and the other is not, and if we're going to deprecate and then remove delete because it's not safe, wouldn't it make more sense to simply make 'delete' memory-safe by giving it the semantics of clear()? By the way, clear() as "clear" would have made more sense if it was effectively destructing then reconstructing the object in place, making it a suitable default implementation of the container-kind clear(). But for what it does right now, it's *clearly* misleading. -- Michel Fortin michel.fortin michelf.com http://michelf.com/clear and delete are very different things. It was definitely decided that we'd be better off without delete. It's going for good. Renaming clear to something that doesn't conflict so easily with more benign functions is completely different from bringing back delete. Bringing back delete isn't even on the table at this point. - Jonathan M DavisWhy can't "delete" do what "clear" does. Backwards compatibility?
May 26 2012
On Saturday, May 26, 2012 14:00:15 Jacob Carlborg wrote:On 2012-05-26 03:38, Jonathan M Davis wrote:I would think that that would be a bad idea, because it wouldn't be doing what delete does in C++ at all and would be really confusing to a lot of people. It would probably work without them realizing what was going on (since it's stupid to do anything with a deleted object other than assign it a new value, which would work with clear), but it would end up with very different behavior memory-wise, causing unexpected behavior. Another problem is that we're trying to discourage using stuff like clear unless you actually need to and know what you're doing, whereas delete is used all the time in C++, because it doesn't _have_ a GC built in. So, having clear as a language construct rather than a function is arguably a bad idea, because it elevates it to something more normal. If it's delete, a lot of people will just use it without learning what's really going on, whereas they'll have to actually learn about clear to use it. Also, it would have a negative effect on ported code to change clear to delete. If delete is illegal, then the compiler will catch it when you forget to remove it from ported code, whereas if it just does what clear does, you could end up with deletes left in when you didn't intend to, but now they have different semantics. - Jonathan M Davisclear and delete are very different things. It was definitely decided that we'd be better off without delete. It's going for good. Renaming clear to something that doesn't conflict so easily with more benign functions is completely different from bringing back delete. Bringing back delete isn't even on the table at this point. - Jonathan M DavisWhy can't "delete" do what "clear" does. Backwards compatibility?
May 26 2012
On 5/25/12 7:30 PM, Mehrdad wrote:On Friday, 25 May 2012 at 20:41:10 UTC, John Chapman wrote:delete also deallocates. AndreiOn Friday, 25 May 2012 at 20:16:32 UTC, Brad Anderson wrote:or we could just, uh, bring back delete...On Fri, May 25, 2012 at 1:34 PM, sclytrack <sclytrack iq87.fr>One for the Doctor Who fans among us: exterminate().blank, destroy, trash, dump, zero, bleach, cleanup, sanitize, burn, nuke, eject, jetisson, discard, landfill, waste, litter, debris, recycle, obliterate, annihilate, eradicate, expunge, finish, ravage, wipe, zap, abolish, decimate, demolish, massacre, murder, ruin, slaughter, quash, scrub, splatI'm partial to defenestrate().
May 25 2012
On 25.05.2012 23:34, sclytrack wrote:blank, destroy, trash, dump, zero, bleach, cleanup, sanitize, burn, nuke, eject, jetisson, discard, landfill, waste, litter, debris, recycle, obliterate, annihilate, eradicate, expunge, finish, ravage, wipe, zap, abolish, decimate, demolish, massacre, murder, ruin, slaughter, quash, scrub, splatI like wipe though obliterate is so much clearer ... :) -- Dmitry Olshansky
May 25 2012
On Sat, 26 May 2012 08:49:19 +0200, Dmitry Olshansky <dmitry.olsh gmail.com> wrote:On 25.05.2012 23:34, sclytrack wrote:I also love obliterate. And annihilate. But I would be more than happy with destroy.blank, destroy, trash, dump, zero, bleach, cleanup, sanitize, burn, nuke, eject, jetisson, discard, landfill, waste, litter, debris, recycle, obliterate, annihilate, eradicate, expunge, finish, ravage, wipe, zap, abolish, decimate, demolish, massacre, murder, ruin, slaughter, quash, scrub, splatI like wipe though obliterate is so much clearer ... :)
May 29 2012
I take it back, dispose is no good. That should be the name of the deterministic destructor in the object. Now I don't have a good name. Finalize isn't right, and neither is dispose... -Stevedisembowel?
May 25 2012
On 5/25/12 22:42 , Steven Schveighoffer wrote:Finalize isn't right, and neither is dispose...In Java it's finalize: http://docs.oracle.com/javase/1.5.0/docs/api/java/lang/Object.html#finalize() In Ruby it's define_finalizer: http://www.ruby-doc.org/core-1.9.3/ObjectSpace.html#method-c-define_finalizer Why not calling finalize then? A bonus is that programmers coming from those languages will find the name more intuitive.
May 25 2012
On Sat, 26 May 2012 02:31:46 -0400, Ary Manzana <ary esperanto.org.ar> wrote:On 5/25/12 22:42 , Steven Schveighoffer wrote:No, this is the GC finalizer. This is equivalent to D's class destructor. We need a function name that denotes *deterministic* destruction.Finalize isn't right, and neither is dispose...In Java it's finalize: http://docs.oracle.com/javase/1.5.0/docs/api/java/lang/Object.html#finalize()In Ruby it's define_finalizer: http://www.ruby-doc.org/core-1.9.3/ObjectSpace.html#method-c-define_finalizerI don't know enough about Ruby to comment, but is this called by the GC? It seems like it is.Why not calling finalize then? A bonus is that programmers coming from those languages will find the name more intuitive.Actually, they will find it confusing, since it doesn't do the same thing. -Steve
May 30 2012
On 25-05-2012 17:37, Steven Schveighoffer wrote:On Fri, 25 May 2012 11:28:07 -0400, Alex Rønne Petersen <alex lycus..org> wrote:But if clear() *does* run the finalizer *now*, then finalize would be a better name, no? I'm all for the dispose model, but then we need a way to suppress finalizers too. -- Alex Rønne Petersen alex lycus.org http://lycus.orgOn 25-05-2012 17:23, Steven Schveighoffer wrote:Yeah, because non-deterministic destruction is part of deterministic destruction. finalize -> destroy non-gc resources dispose -> 1. do deterministic destruction involving possible GC resources 2. call finalize. e.g. a buffered file: finalize -> close the file handle dispose -> flush the GC allocated buffer into the handle, then close the handle -SteveOn Fri, 25 May 2012 11:03:33 -0400, Alex Rønne Petersen <alex lycus..org> wrote:But it calls rt_finalize...?On 25-05-2012 16:56, Steven Schveighoffer wrote:I don't like finalize because it's not a finalizer. I think we should mimic other languages that have a finalizer and a deterministic dispose function. -SteveWow, you're right, it's not documented. That should be fixed!Before we do, we should deprecate clear and rename it to finalize, though.
May 25 2012
On Fri, 25 May 2012 11:42:57 -0400, Alex R=C3=B8nne Petersen <alex lycus= .org> = wrote:On 25-05-2012 17:37, Steven Schveighoffer wrote:On Fri, 25 May 2012 11:28:07 -0400, Alex R=C3=B8nne Petersen <alex lycus..org> wrote:On 25-05-2012 17:23, Steven Schveighoffer wrote:On Fri, 25 May 2012 11:03:33 -0400, Alex R=C3=B8nne Petersen <alex lycus..org> wrote:On 25-05-2012 16:56, Steven Schveighoffer wrote:Wow, you're right, it's not documented. That should be fixed!Before we do, we should deprecate clear and rename it to finalize,=though.I don't like finalize because it's not a finalizer. I think we should mimic other languages that have a finalizer and a=theYeah, because non-deterministic destruction is part of deterministic destruction. finalize -> destroy non-gc resources dispose -> 1. do deterministic destruction involving possible GC resources 2. call finalize. e.g. a buffered file: finalize -> close the file handle dispose -> flush the GC allocated buffer into the handle, then close =deterministic dispose function. -SteveBut it calls rt_finalize...?a =handle -SteveBut if clear() *does* run the finalizer *now*, then finalize would be =better name, no? I'm all for the dispose model, but then we need a way to suppress =finalizers too.This is what I think clear (or function to be named later) should do: if(obj.dispose()) rt_finalize(obj); else rt_suppressFinalize(obj); That way you can write code like this: class File { bool dispose() { flush(); return true; } ~this() { close(handle); } } and you don't have to repeat the finalize code inside the dispose routin= e = if it's a normal part of deterministic destruction. -Steve
May 25 2012
On 25-05-2012 17:59, Steven Schveighoffer wrote:On Fri, 25 May 2012 11:42:57 -0400, Alex Rønne Petersen <alex lycus..org> wrote:Sounds good to me. -- Alex Rønne Petersen alex lycus.org http://lycus.orgOn 25-05-2012 17:37, Steven Schveighoffer wrote:This is what I think clear (or function to be named later) should do: if(obj.dispose()) rt_finalize(obj); else rt_suppressFinalize(obj); That way you can write code like this: class File { bool dispose() { flush(); return true; } ~this() { close(handle); } } and you don't have to repeat the finalize code inside the dispose routine if it's a normal part of deterministic destruction. -SteveOn Fri, 25 May 2012 11:28:07 -0400, Alex Rønne Petersen <alex lycus..org> wrote:But if clear() *does* run the finalizer *now*, then finalize would be a better name, no? I'm all for the dispose model, but then we need a way to suppress finalizers too.On 25-05-2012 17:23, Steven Schveighoffer wrote:Yeah, because non-deterministic destruction is part of deterministic destruction. finalize -> destroy non-gc resources dispose -> 1. do deterministic destruction involving possible GC resources 2. call finalize. e.g. a buffered file: finalize -> close the file handle dispose -> flush the GC allocated buffer into the handle, then close the handle -SteveOn Fri, 25 May 2012 11:03:33 -0400, Alex Rønne Petersen <alex lycus..org> wrote:But it calls rt_finalize...?On 25-05-2012 16:56, Steven Schveighoffer wrote:I don't like finalize because it's not a finalizer. I think we should mimic other languages that have a finalizer and a deterministic dispose function. -SteveWow, you're right, it's not documented. That should be fixed!Before we do, we should deprecate clear and rename it to finalize, though.
May 25 2012
Am 25.05.2012 15:04, schrieb Alex Rønne Petersen:So I was writing a container class and in some test code, I called container.clear(). Reasonable enough, right? Hell, it even compiled! Turns out, my program completely broke at runtime. Apparently, I'd forgotten to implement clear() on my container class, and *object.clear() was being called instead*. I don't blame UFCS for this. It just happened to be the reason this compiled at all. But, what I do think is: clear is the *ABSOLUTELY MOST HORRIBLE NAME EVER* for a function that actually finalizes and zeroes an object. Did it not seem obvious to call it, I don't know, *finalize*? And even ignoring the naming, having a symbol called clear in the 'global' namespace is absolute insanity. Am I the only person with this opinion?I completely agree! Had the same situation before... Also I hate that UFCS is doing the same thing that properties did in the beginning and have no way to enforce a specific usage. I strongly believe that it is a (often important) decision of the library architect if a function is to be called normally or as member function style.
May 25 2012
On 05/25/12 18:11, Sönke Ludwig wrote:Am 25.05.2012 15:04, schrieb Alex Rønne Petersen:method ? arturSo I was writing a container class and in some test code, I called container.clear(). Reasonable enough, right? Hell, it even compiled! Turns out, my program completely broke at runtime. Apparently, I'd forgotten to implement clear() on my container class, and *object.clear() was being called instead*. I don't blame UFCS for this. It just happened to be the reason this compiled at all. But, what I do think is: clear is the *ABSOLUTELY MOST HORRIBLE NAME EVER* for a function that actually finalizes and zeroes an object. Did it not seem obvious to call it, I don't know, *finalize*? And even ignoring the naming, having a symbol called clear in the 'global' namespace is absolute insanity. Am I the only person with this opinion?I completely agree! Had the same situation before... Also I hate that UFCS is doing the same thing that properties did in the beginning and have no way to enforce a specific usage. I strongly believe that it is a (often important) decision of the library architect if a function is to be called normally or as member function style.
May 25 2012
On Friday, May 25, 2012 15:04:16 Alex R=C3=B8nne Petersen wrote:So I was writing a container class and in some test code, I called container.clear(). Reasonable enough, right? Hell, it even compiled! =20 Turns out, my program completely broke at runtime. Apparently, I'd forgotten to implement clear() on my container class, and *object.clear() was being called instead*. =20 I don't blame UFCS for this. It just happened to be the reason this compiled at all. But, what I do think is: clear is the *ABSOLUTELY MO=STHORRIBLE NAME EVER* for a function that actually finalizes and zeroes=anobject. Did it not seem obvious to call it, I don't know, *finalize*?=And even ignoring the naming, having a symbol called clear in the 'global' namespace is absolute insanity. =20 Am I the only person with this opinion?https://github.com/D-Programming-Language/druntime/pull/231
May 29 2012
On 30-05-2012 08:43, Jonathan M Davis wrote:On Friday, May 25, 2012 15:04:16 Alex Rønne Petersen wrote:Thanks! -- Alex Rønne Petersen alex lycus.org http://lycus.orgSo I was writing a container class and in some test code, I called container.clear(). Reasonable enough, right? Hell, it even compiled! Turns out, my program completely broke at runtime. Apparently, I'd forgotten to implement clear() on my container class, and *object.clear() was being called instead*. I don't blame UFCS for this. It just happened to be the reason this compiled at all. But, what I do think is: clear is the *ABSOLUTELY MOST HORRIBLE NAME EVER* for a function that actually finalizes and zeroes an object. Did it not seem obvious to call it, I don't know, *finalize*? And even ignoring the naming, having a symbol called clear in the 'global' namespace is absolute insanity. Am I the only person with this opinion?https://github.com/D-Programming-Language/druntime/pull/231
May 30 2012