I don't like the example no. 1, bcause of ith generic name.
conditionMet
does not seem to be generic, so it stands for a specific condition? Like
isAdult () = {
age >= 18
}
This would be fine. It's a semantic difference, while
isAtLeast18 () { age >= 18; }
would not be fine for me.
Maybe it is often used, and can be subject for later change:
getPreferredIcecream () { return List ("banana", "choclate", "vanilla", "walnut") }
is fine too. Using it multiple times, you just need to change a single place, if you have to - maybe whipped cream gets possible tomorrow.
isXYZ (Foo foo) { foo.x > 15 && foo.y < foo.x * 2 }
is not atomic, and should give you a nice test opportunity.
If you need to pass a function, of course, pass whatever you like, and write otherwise silly looking functions.
But in general, I see much more functions, which are too long, than functions which are too short.
A last word: Some functions only look appropriate, because they're written too verbose:
function lessThan (a, b) {
if (a < b) return true else return false;
}
If you see, that it is the same as
return (a < b);
you won't have a problem with
localLessThan = (a < b);
instead of
localLessThan = lessThan (a, b);
Assert.AreEqual<int>(expected, actual, message, arg1, arg2, arg3, ...);
. The second one is fine as is. I would potentially include an optional bool flag which would dictate whether to throw an exception/etc. in case the callback is not a function.def yes(): return 'yes'