clear() and UFCS

deadalnix deadalnix at gmail.com
Fri May 25 08:11:51 PDT 2012


Le 25/05/2012 17:00, Andrei Alexandrescu a écrit :
> On 5/25/12 8:06 AM, Dmitry Olshansky wrote:
>> 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.
>
> Since this is a recurring issue we should probably change the name.
>
> Andrei
>
>

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.


More information about the Digitalmars-d mailing list