http://d.puremagic.com/issues/show_bug.cgi?id=3923



--- Comment #4 from bearophile_h...@eml.cc 2010-08-07 06:30:59 PDT ---
It's not just a problem of documentation. std.algorithm is modelled on the C++
STL algorithms, they are efficient and they are useful in many cases. But not
all D programmers are familiar with STL and sometimes C++ API design isn't the
best conceivable. The good Python-inspired API of std.string shows that a good
"ergonomic" API design allows you a handy string processing. So I suggest to
add to the STL-style API design of std.algorithm a more human style, not
inspired by C++ and inspired by more user-oriented languages.

This proposal of mine looks not precise, so I can express the ideas in a more
defined way.

As with most software it's better to first ask yourself what your software will
mostly be used for, and then to write it. Otherwise you are wasting your time
and the user time.

>From my experience here are the most common usages for find-like functions
(every one of the following seven operations takes an optional transform
function like schwartzSort), (some of them are already present in std.algorithm
with a different name):

1) boolean predicate, is the item/iterable x inside the iterable foo?
(built-"in" operator for arrays, because this is a really common operation. Or
if not possible a "isIn" function).
2) int function, tell me how many items/arrays x are inside the iterable foo
("count" function).
3) int function, tell me the index of the first item/iterable x in the iterable
foo ("index" function).
4 extra) find lazily all the indexes of an item/iterable x inside the iterable
foo ("indexes" struct or class).

5) find the first max/min item in a iterable ("max", "min" functions, they have
overloads for 2 and 3 items too).
6) find the index of the max/min item in a iterable ("maxPos", "minPos"
functions).
7) find lazily all the max/min items in a iterable ("maxs", "mins" structs or
classes).


Here I call 'iterable' a Range (like a string, array, AA, etc) or a
struct/class that defines just opApply.

In the first 4 micropatterns it's positive to have a specialization for
strings, to increase performance with some string-specific tricks. Such
specializations are fitter for the std.string module.

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

Reply via email to