The latest trunk has numerous custom #isEmpty implementations, but that doesn't help custom collections outside the image not inheriting one. I maintain cross-platform projects that have such collections, like XPath with XPathFunctionSet or the BitmapCharacterSet package it relies on. Both are Collection subclasses, and now I feel like I should add this: isEmpty ^ self size = 0
to every single collection I maintain. Why not just make #size a subclassResponsibility or add abstract superclasses for lazy or infinite collections that implement #isEmpty using #do: and change #size to shouldNotImplement?
Sent: Saturday, October 22, 2016 at 8:42 AM From: "Nicolas Cellier" nicolas.cellier.aka.nice@gmail.com To: "The general-purpose Squeak developers list" squeak-dev@lists.squeakfoundation.org Subject: Re: [squeak-dev] Re: The defaullt implementation of isEmpty might do too much work
Please retry with latest trunk version.
2016-10-22 6:48 GMT+02:00 monty monty2@programmer.net:Putting #size-based implementations in abstract Collection subclasses negates the lazy collection benefit and still penalizes non-abstract direct Collection subclasses like CharacterSet and any user-defined direct Collection subclass implemented using composition with forwarding to a concrete collection. If the default linear complexity of #size and #isEmpty bothers you so much, make #size a subclassResponsiblity like #do: instead of suddenly penalizing collections whose authors actually did the right thing by providing a non-linear #size implementation.
Sent: Friday, October 21, 2016 at 11:26 PM From: "Eliot Miranda" eliot.miranda@gmail.com To: "The general-purpose Squeak developers list" <squeak-dev@lists.squeakfoundation.org[mailto:squeak-dev@lists.squeakfoundation.org]> Subject: Re: [squeak-dev] Re: The defaullt implementation of isEmpty might do too much work
Hi Monty,
what happens if you add an isEmpty implement ration based in size to SequenceableCollection?
_,,,^..^,,,_ (phone)
On Oct 21, 2016, at 3:59 PM, monty monty2@programmer.net wrote:
All non-trivial collections implement #size or inherit a custom implementation, usually just as a return of an inst var. Your #do:-based one is 3x as slow in my tests, so you've now made #isEmpty slower for every collection that implements #size just to benefit ones whose careless authors didn't and so the implementors of lazy collections have one fewer message to override.
Do not do this. People already avoid #ifEmpty: and related messages where performance matters and shouldn't have to avoid #isEmpty too.