Hi Ben,

Just to complete Sven's answer: #new will send #initialize to the new
instance. Some frameworks may not want that to avoid extra initializations
or side-effects. Think for example about any kind of serializer like Fuel
or Glorp: the object they serialize/deserialize already have state, there
is no need to execute the #initialize method on them.

Now, checking the cases you show in the first email:

 - Case 1: could probably call #new
 - Case 2: I don't know without checking the code :)
 - Case 3: could probably call #new

I think Cases 1 and 3 are just optimizations. They avoid #new to avoid the
extra (empty) call to #initialize. Sista should fix this by smartly
inlining the #initialize methods thus avoiding extra overhead for these
cases...

That said, I'd say that
 - people should not use #basicNew, unless they know what they are doing
and why.
 - corollary: if you do not know what to use, use #new

That will avoid headaches like "My object is not initialized ñaañaña" :)

Guille

On Tue, May 30, 2017 at 8:16 AM, Ben Coman <[email protected]> wrote:

>
>
> On Tue, May 30, 2017 at 2:05 PM, K K Subbu <[email protected]> wrote:
>
>> On Sunday 28 May 2017 02:09 PM, Ben Coman wrote:
>>
>>> Thanks Subbu.  That is a useful insight for me, but is about the
>>> implementation.
>>> My query was more about senders of basicNew, so is still open if you
>>> have an opinion there, or anyone else.
>>>
>>
>> It is just a private primitive for creating new instances. I don't think
>> there is any restriction in the language that it should only be sent only
>> from class-side methods. Only methods which are part of language
>> implementation will send this selector and it so happens that most callers
>> fall on the class side. You will also find instance side methods
>> (operators) in non-trivial basic types like Colors or DateAndTime sending
>> #basicNew.
>>
>> Regards .. Subbu
>>
>>
> Cool. Sounds like I was being over-eager then.
> cheers -ben
>
>


-- 



Guille Polito


Research Engineer

French National Center for Scientific Research - *http://www.cnrs.fr*
<http://www.cnrs.fr>



*Web:* *http://guillep.github.io* <http://guillep.github.io>

*Phone: *+33 06 52 70 66 13

Reply via email to