"Consume", "Skip", "Eat", "Munch", "Bite", or...?

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Sat Feb 20 12:48:10 PST 2010


To focus the discussion about naming conventions, let's discuss one 
particular aspect. Right now we have in std.algorithm:

=======================
/**
If the range $(D doesThisStart) starts with $(I any) of the $(D
withOneOfThese) ranges or elements, returns 1 if it starts with $(D
withOneOfThese[0]), 2 if it starts with $(D withOneOfThese[1]), and so
on. If no match, returns 0.

Example:
----
assert(startsWith("abc", ""));
assert(startsWith("abc", "a"));
assert(!startsWith("abc", "b"));
assert(startsWith("abc", 'a', "b") == 1);
assert(startsWith("abc", "b", "a") == 2);
assert(startsWith("abc", "a", "a") == 1);
assert(startsWith("abc", "x", "a", "b") == 2);
assert(startsWith("abc", "x", "aa", "ab") == 3);
assert(startsWith("abc", "x", "aaa", "sab") == 0);
assert(startsWith("abc", "x", "aaa", 'a', "sab") == 3);
----
  */
uint startsWith(alias pred = "a == b", Range, Ranges...)
(Range doesThisStart, Ranges withOneOfThese);
=======================

I also defined recently:

=======================
/**
If $(D startsWith(r1, r2)), consume the corresponding elements off $(D
r1) and return $(D true). Otherwise, leave $(D r1) unchanged and
return $(D false).
  */
bool startsWithConsume(R1, R2)(ref R1 r1, R2 r2);
=======================

There are a few other functions like that: one version takes a range by 
value, the other takes it by reference and alters it.

The question is, what is a good naming convention for expressing that? 
Other examples: findConsume, consumeFind.


Andrei



More information about the Digitalmars-d mailing list