On Thu, 14 May 2009 16:51:27 -0400, Walter Bright
<newshou...@digitalmars.com> wrote:
Steven Schveighoffer wrote:
I could never understand the mentality of returning -1 versus end of
string.
It's not -1, it's uint.max. The reason for returning that value is that
it is the only integer value that can never be a valid index.
Pretty sure uint.max - 1 is also invalid (as well as a host of other
values) ;)
but in any case, it's much less useful than str.length, as you can't
directly use it, you simply have to check for it. If all you ever do is
check to see if it's a certain value, why does it have to be uint.max?
I guess I understand the mentality of picking -1 or uint.max as a
reasonable "failure" return, but what I don't understand is why you would
do so when you could use the length of the string, which is useful for
many other purposes. -1 or uint.max just is a failure, and needs to be
checked, it can't be used to do any slicing operations.
I always hated doing string processing with Java vs. C++ because of this.
-Steve