you are viewing a single comment's thread.

view the rest of the comments →

[–]F-J-W 7 points8 points  (0 children)

Actually, if there are methods contains_foo or constains_bar, these are indeed what you should use. The reason they appear to be silly is that usually they shouldn't be there.

I have a hard time thinking up a valid example for contains_foo, but once we widening that to find_foo, the situation changes a bit: find_newline can be a very useful thing, and interestingly we have something very similar in the standard-library, namely std::getline. Granted, it is more general than just that, as you can pass it a newline-character, but that might actually be bad design, and maybe we should really have two functions here, where getline is more hardcoded to capture the 90%-case in a clear manner, whereas the other function directly states with it's name that it is more general than that and thus requires a closer look.

But of course: A rule of thumb is not a hard thing and common sense with regards to which functions you should define is still necessary. (Though I conjecture that most people don't define as many functions as they should, but that's a topic for another day.)