Kinds of containers
Timon Gehr via Digitalmars-d
digitalmars-d at puremagic.com
Mon Oct 26 13:46:20 PDT 2015
On 10/26/2015 08:31 PM, Ulrich Küttler wrote:
> On Wednesday, 21 October 2015 at 18:49:26 UTC, Andrei Alexandrescu wrote:
>> On 10/21/2015 12:25 PM, Jonathan M Davis wrote:
>>> My experience with immutable containers is that their performance is
>>> trash precisely because you can't mutate them.
>>
>> That's actually the experience in the Scala community. Over and again
>> people start with immutable containers all over the place because
>> they're cool, and end up with mutable containers because they work. --
>> Andrei
>
> Ranges and loops. Same story. Ranges are cool, loops get stuff done.
>
This kind of reasoning sounds cool but is ultimately misguided.
(I don't think the stories are even analogous.)
Persistent containers have a /different interface/ than mutable
containers and hence can be used in different algorithms, where they can
help getting low asymptotic resource usage. Obviously there is not much
point in using persistent containers just because one considers them
"cool" if what one really wants is a mutable container.
Ranges can be iterated, loops iterate them. If one wants to get stuff
done, one uses library primitives when they apply and implements the
remaining functionality oneself. When one notices that certain patterns
begin to repeat, one will sometimes take a short time to factor them out
in order to make progress faster. If they are patterns of iteration,
this means writing an opApply or sometimes a range.
More information about the Digitalmars-d
mailing list