<div dir="ltr"><div dir="ltr">Juan,</div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Sep 30, 2019 at 4:51 PM Juan Vuletich <<a href="mailto:juan@jvuletich.org">juan@jvuletich.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><u></u>

  
    
    
  
  <div bgcolor="#ffffff">
    (inline)<br>
    <br>
    On 9/30/2019 4:46 PM, Phil B wrote:
    <blockquote type="cite">
      <div dir="ltr">OK, now I understand what you are going for... this
        seems like a convenience optimization in the wrong place. 
        Wouldn't it make more sense to have this logic in something like
        #elementSpecies?  </div>
    </blockquote>
    <br>
    No, this is not what I tried to do. 'Color red species = FloatArray'.<br></div></blockquote><div><br></div><div>But you're doing it so that you can return one or more *elements* of a Color as you indicate below...</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div bgcolor="#ffffff">
    <br>
    <blockquote type="cite">
      <div dir="ltr">Most of my code that uses #species with collections
        is expecting it to return what kind of collection it should use
        when creating some sort of collection-based copy/result, not an
        individual element.  </div>
    </blockquote>
    <br>
    That is exactly what I tried to do. For instance, Color is a suclass
    of FloatArray, that adds the restriction that it must have 3
    elements. TranslucentColor is similar, but must be of size = 4. If
    you do a #select: on them, the answer could have less than 3 (or 4)
    elements, and then, the correct class for the answer is FloatArray
    and not Color. See what happens with 'Color red select: [ :v | v
    > 0.5 ]'.<br></div></blockquote><div><br></div><div>Right, you want to perform an operation returning one or more of its elements rather than a (new/existing) Color.  Unless I'm missing something, you're not really interested in the type of the 'containing' object but rather it's elements.  I'm not arguing that there's anything wrong with wanting to take this view, but it does seem inconsistent with how #species is defined and generally used elsewhere.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div bgcolor="#ffffff">
    <br>
    Does this reasoning apply to the examples you are seeing?<br></div></blockquote><div><br></div><div>No, the typical use case I am seeing would be (using Color as an example) to create a new instance of a Color without assuming that the class of the object being passed in is the class to use to create a new instance.  The two main cases in my code seem to be:</div><div><br></div><div>1) You have polymorphic subtypes where the subtypes have #species return the parent type.  The parent class then decides which subclass to actually use at instantiation time based on the parameters provided.</div><div><br></div><div>2) You have a specialized subtype that you generally don't want (or can't be) instantiated as an instance of self class, but rather a more generic supertype.</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div bgcolor="#ffffff">
    <br>
    <blockquote type="cite">
      <div dir="ltr">Also, sometimes the collection *is* the element
        (i.e. Vector*) as far as most code is concerned.</div>
    </blockquote>
    <br>
    Not sure how this relates to what #species answers... Maybe
    elaborate a bit on this.<br></div></blockquote><div><br></div><div>The shortest way I can explain it is to point to the comment in Object>species.  When you want to recreate a Color, you want the class Color used, not FloatArray.</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div bgcolor="#ffffff">
    <br>
    <blockquote type="cite">
      <div dir="ltr">
        <div>Lots of FFI code uses ArrayedCollection subclasses for
          buffers of various types and you typically want #species to
          return the appropriate collection type (not always of the same
          class) when doing something with it. <br>
        </div>
      </div>
    </blockquote>
    <br>
    Exactly. Besides, any collection class is free to redefine #species
    appropriately.<br></div></blockquote><div><br></div><div>That's my argument: I don't think your override for ArrayedCollection fits... it's a different kind of use case you're defining.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div bgcolor="#ffffff">
    <br>
    <blockquote type="cite">
      <div dir="ltr">
        <div> It also seems a bit weird for ArrayedCollection to
          sometimes return the class of its elements while other
          collections return the class of the collection itself (which
          it pretty much has to for heterogeneous collections.)</div>
      </div>
    </blockquote>
    <br>
    It should always be a collection class, that is appropriate as a
    result.<br>
    <br>
    The problem I do see is that, perhaps, 'Color red collect: [ :v | v
    / 2 ]' could answer an instance of Color. So maybe  we could make
    the search for an appropriate superclass in a separate message, like
    #speciesForPotentiallyShorterResult (uhg that's ugly), and only call
    this other method from #select:, but not from #collect: or #=.<br></div></blockquote><div><br></div><div>Yep, that's what I was suggesting but not with the most accurate name.  How about something like #elementContainerSpecies? (I *think* this would only apply to the ArrayedCollection hierarchy rather than something higher up, right?)</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div bgcolor="#ffffff">
    <br>
    Thanks,<br>
    <pre cols="72">-- 
Juan Vuletich
<a href="http://www.cuis-smalltalk.org" target="_blank">www.cuis-smalltalk.org</a>
<a href="https://github.com/Cuis-Smalltalk/Cuis-Smalltalk-Dev" target="_blank">https://github.com/Cuis-Smalltalk/Cuis-Smalltalk-Dev</a>
<a href="https://github.com/jvuletich" target="_blank">https://github.com/jvuletich</a>
<a href="https://www.linkedin.com/in/juan-vuletich-75611b3" target="_blank">https://www.linkedin.com/in/juan-vuletich-75611b3</a>
@JuanVuletich</pre></div></blockquote><div><br></div><div>Thanks,</div><div>Phil </div></div></div>