[Gambas-user] New feature in the Array classes

Tobias Boege tobs at taboege.de
Sat Feb 13 01:07:57 CET 2021


On Sat, 13 Feb 2021, Brian G wrote:
> 
> But if you just used a sorted array, it would always be sorted. No need of any conversion.. or special functions. 
> Ummmm, and if you updated your code to use one, then you just change one place.. the definition, all the interface calls are pretty much the same

Remixing the ideas from this subthread, this feature could also take the
form of a virtual class named .Array.Sorted which replaces some of the
methods with more optimized or specialized ones. You would then write
aThings.Sorted.Add(...) or aThings.Sorted.Find(...) if you want to treat
the array as sorted and preserve that property.

To me, this reads nicer than aThings.AddSorted etc. and doesn't show up
immediately in the Array class help. It would also avoid copying data,
because a virtual class operates on the same underlying object, it just
changes the method resolution.

The disadvantage (which I cannot quantify!) would be that virtual class
access is slower because it adds one level of indirection. It's basically
a less efficient way of passing an optional flag to a method, except that
it is totally backwards-compatible and doesn't clutter the class's symbols.

Just a thought.

Regards,
Tobias

-- 
"There's an old saying: Don't change anything... ever!" -- Mr. Monk


More information about the User mailing list