[Issue 10959] std.algorithm.remove is highly bug-prone

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Jan 9 03:12:03 PST 2014


https://d.puremagic.com/issues/show_bug.cgi?id=10959



--- Comment #6 from bearophile_hugs at eml.cc 2014-01-09 03:11:59 PST ---
In Python to remove an item from an array (list) you use:

>>> items = [10, 20, 30, 20]
>>> items.remove(20)
>>> items
[10, 30, 20]


With D+Phobos you need:

void main() {
    import std.stdio, std.algorithm;
    auto items = [10, 20, 30, 20];
    items = items.remove(items.countUntil(20));
    items.writeln;
}


So this API is quite bad all around, it's not just bug-prone.

So I suggest to introduce a differently named function that works similarly to
the current remove (but it doesn't need the bug-prone re-assignment on the
left):

items.removeAtIndex(1);

And modify remove() to work like this, as the Python remove method:

items.remove(20);

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list