|
Boost : |
From: Rob Stewart (stewart_at_[hidden])
Date: 2003-10-29 10:17:55
From: "Andy Little" <andy_at_[hidden]>
> "Pavol Droba" <droba_at_[hidden]> wrote in message
> news:20031029071346.GO5420_at_lenin.felcer.sk...
> > On Wed, Oct 29, 2003 at 12:09:23AM -0000, Andy Little wrote:
> > > "Ross MacGregor" <ross__macgregor_at_[hidden]> wrote in message
> > > news:bnmmlm$vsd$1_at_sea.gmane.org...
> > > > Rob Stewart wrote:
> > > > > From: David Abrahams <dave_at_[hidden]>
> > > > >
> > > > >>I don't get it. The first element of a sequence is s[0]. Why
> > > > >>shouldn't the first matching substring be find_nth(s, XX, 0)?
> > > > >
> > > > > Because s[0] isn't the 0th element; it's the first. As I said,
> > > > > we use ordinals to refer to things like this. Addressing an
> > > > > element uses an index, and indexes start at zero. "nth"
> > > > > explicitly refers to ordinals, and there's no 0th; you start with
> > > > > 1st, so find_nth() should reasonably start numbering from one.
> > > >
> > > > Yes agree with Rob on this one. I have been using 0 based indexes for
> a
> > > > long long time, but when i see find_nth(), I expect 1 to be the first
> > > > occurence.
> > > >
> > > > I think in this case naming guidlines should override convention or
> > > > usage concerns. If you use a term like "nth" in the name, it should
> > > > reflect its usage in the english language.
> > >
> > > "offset" does it for me... find_offset() ...?
> >
> > If just a name is confusing, I have no problem to rename it. However the
> problem
> > would be to find the better name. I don't like find_offset. It does not
> > decsribe what it is suppose to do.
I agree.
> The real issue is the equation "first" == 1 or "first" == 0;
> Surely there is only one 'first' that fits C/C++ here:
>
> for (int n = 0; n < lim ; ++n) {
> if (match(n)){
> find_nth(cont,str,n);
> }
> }
I couldn't disagree more. Were I reviewing that code without
knowing a priori that find_nth() used zero-based numbering, I'd
flag that as an error. The *name* find_nth() invokes ordinals
and there's no 0th. One poster suggested that the year before
one's first birthday, is the 0th year. Sorry, but I've never
heard anyone mention the 0th year of a child's life.
If you change "nth" in "find_nth" to something else, or rename
the function altogether, we avoid the confusion.
> ding dong ding dong ... but hope this now makes 3 to 2 for 'first' ==
> 0 ... :-)
That the count is so close -- though it's hardly statistically
meaningful yet -- should be enough to make us all uncomfortable
with "find_nth."
Many libraries and languages have an operation called "index"
which finds a numbered occurrence of a substring in a string. I
would fully expect zero-based numbering in such a function.
-- 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