New ranges and algorithms

Philippe Sigaud philippe.sigaud at gmail.com
Tue Dec 22 12:13:03 PST 2009


bearophile Wrote:

> Philippe Sigaud:
> > http://www.dsource.org/projects/dranges/
> 
> This can improve Phobos2 some. But it's really important that functions written by Andrei, you 
> and other people are tested inside real code (even better is when real code asks for their creation, 
>so they are born from practical necessity). 

Well,it's born from my own needs indeed, if that's reassuring. As far as possible, when I found something useful, I tried to factor it into different generic parts and put them there. Now, my needs are strictly personal (at one times, that was to do the Euler Project problems) and my job is quite far away from these considerations. I don't consider this to be 'real life' indeed.

But I regularly find myself in need of mapping n ranges in lockstep or filtering them, or extracting n-elements subranges from a range, so I gather some functions there could be useful. And you can find equivalent functions in nearly all PL that have a concept of sequence/range. So I found it interesting to write them in D, to get some feeling as to how it could be done.


>Because it's easy to invent functions that are not easy to remember, not useful enough, 
>that are not flexible enough, that are too much flexible, etc. 
>The "API" must be small otherwise it's hard to remember the functions and their names, 
>but it has to be flexible enough, etc.

Hmm, yes? Can you tell me if you think the 'API' is OK? API is a big word for simple 1-2 parameters functions. I guess that, if people understand take(2, range) they will understand merge(range1, range2) or combinations(range1, range2, range3)...

I think we already had this discussion. For me, it's a three-steps process

1- get the code to do what I need right now
2- come back later, see the common patterns, factor them away and make them generic
3- then, when common uses come again and again, write a function that associate the generic function
in a useful, practical, commonly-used way.

But, you know, I'm still learning while doing this project, so I'm pretty sure there still much room for improvements.

  Philippe




More information about the Digitalmars-d-announce mailing list