|
Boost : |
From: Rob Stewart (stewart_at_[hidden])
Date: 2003-10-31 15:39:26
From: Pavol Droba <droba_at_[hidden]>
> On Thu, Oct 30, 2003 at 03:20:32PM -0500, Rob Stewart wrote:
> > From: "Peter Dimov" <pdimov_at_[hidden]>
>
> > Given my now enlightened understanding of nth_element, I don't
> > consider it analogous to find_nth() at all, so you can consider
> > all of my capitulation above rescinded!
> >
> > Choosing a different name will resolve the problem as previously
> > stated.
>
> There has been a lot of arguments propesed in this matter, but I would
> still prefer the current solution. The reasons are following:
>
> Naming:
>
> - It is clear what does it mean n-th element (modulo indexing problem).
> So it is clear what does find_nth() do.
Each user of find_nth() will think it is clear what it will do,
but the results will surprise many because of the index versus
ordinal problem. Therefore, it is *not* clear what find_nth()
does apart from reading the docs and smacking yourself each time
you do the wrong thing (until it finally sticks).
Again, this will affect one group or the other, depending upon
whether find_nth() numbers from zero or one.
> - find_index() implies that we are searching for an index not an element of
> substring.
>
> - find_occurence() is a very synonym of find(), it provides no information
> about what occurence is actualy found
You missed my suggestion: index(). The very name suggests the
use of indexes and is supported by prior art in other languages.
> Indexing:
>
> - 0-based index is widely accepted and understood by C/C++ developers.
> - all C/C++ entities which use an indexing in some way use 0-based indexing
>
> - even if 1-based index can sound more natural, I thing that breaking heavily
> used convention is match worse.
As I've said repeatedly, I have no problems with zero based
indexes. I've used C++ for many, many years (not to mention
other languages that start counting at zero). It isn't the least
bit uncomfortable for me. What is a problem is that a function
named "find_nth" refers to ordinals and *there is no 0th* of
anything, no matter how hard one wishes it were so.
> - if the parameter name is changed to "index" it is clear, what base should be used
Nope. That doesn't tell me anything about this line of code:
yada = find_nth(.., 2);
Will that return the second or third match? If a maintenance
programmer doesn't know find_nth(), he might assume that it
returns the third match. Too bad for him. He'll waste hours
wondering why the "obvious" isn't working.
> Over and out.
Too bad. You're convinced you're right and it's your library, so
do what you want. That doesn't fix the problem, however.
-- Rob Stewart stewart_at_[hidden] Software Engineer http://www.sig.com Susquehanna International Group, LLP using std::disclaimer;
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk