Am 22.04.2011 20:53, schrieb Leigh Johnston:
On 22/04/2011 19:26, Peter Remmers wrote:
Am 22.04.2011 17:56, schrieb Leigh Johnston:
On 22/04/2011 16:25, Paul wrote:
[criticism to Leigh's code]
*plonk*
I don't endorse Paul's way of attacking your code, but at the core of
his criticism, I actually have to agree. I think that it is way too
verbose, and therefore unreadable, for the simple task it is supposed to
do.
I disagree; it is not too verbose when you consider it is a general
utility function designed to solve a general problem (you can specify a
maximum token count; treat the delimiters as a subsequence as well as a
list of delimiters; and to discard empty tokens) rather than the OP's
specific problem even though it can be used to solve that specific
problem. Paul The Troll's criticism was a nonsense as I do not iterate
through the source buffer more than once which he claimed.
I forgot to mention that the same function can also tokenize into pairs
of iterators rather making sub-string copies which has obvious
performance benefits; as I said it is a general (iterator based)
solution to a general problem rather than a specific solution to a
specific problem. One should strive to solve problems in as generic a
way as possible especially when designing library functions (which my
solution is).
So your function is a "swiss army knife"...
The more generic a function/class/library becomes, the more of a monster
it becomes.
I think a function should focus on a single task. If you need a function
that does something different, write another function.
Why do you think there are different variations of find() in the STL,
such as find_first_of(), find_last_of(), find_if(), etc.?
You would have written a single find() function that you can parametrize
with all sorts of stuff.
KISS.
That said. I think it is too big for what it does. Or it tries to do too
much at once. Pick one.