std.container & ranges

Jonathan M Davis jmdavisProg at gmx.com
Sun Oct 30 20:28:46 PDT 2011


On Monday, October 31, 2011 12:11:45 Mike Parker wrote:
> On 10/31/2011 5:28 AM, Jonathan M Davis wrote:
> > So, in comparison to C++, there's no significant difference. Now, Java
> > does have a remove function which will take an element and remove the
> > first occurence of that element from a list, and we could theoretically
> > add one, but why?
> IMO, it's much more intuitive to say list.remove(item). It's the first
> thing a lot of people expect coming from a Java background, that's for
> sure. The first time I tried to use SList, being unfamiliar with ranges
> as I was, it took a while to figure out what I needed to do. IIRC, I had
> to post here to ask.
> 
> The problem is that you really have to understand ranges and the Phobos
> functions that manipulate them before you can begin to use containers. I
> think that's wrong. Ideally, containers should be usable without having
> to know about find and Take and whatever else. This isn't the first time
> this question has come up in the NG and I've got a feeling it won't be
> the last.
> 
> At the very least it would be nice to see something in the documentation
> tying std.algorithm and std.range together with std.container. Something
> to point the way for those to whom it isn't obvious.

I definitely agree that the documentation should be improved to at least give 
the basic example of using find with linearRemove. Adding something similar to 
C++'s remove_if which removes all elements which match a predicate could also 
be useful, but I don't at all agree that there should be a function which 
takes an element and removes the first element which is equal to it. find allows 
you to do that just fine, and such a remove function would simply be 
duplicating its functionality.

As for understanding ranges, it's definitely true that there needs to be more 
documentation and/or articles on them so that the concept can better 
communicated. That's a definite flaw in the current documentation. But there's a 
lot in Phobos which you're just not going to be able to use if you don't 
understand ranges, and the library would definitely be worse if it used them 
less, since they're such a powerful concept, so I think that the problem is 
the lack of communication on ranges, not the fact that ranges are used so 
heavily in Phobos.

- Jonathan M Davis


More information about the Digitalmars-d-learn mailing list