Your second example doesn't compile; you're using too much if
s.
If you would be looking what the compiler would make of it, there wouldn't be too much of a difference; the &&
operator short-circuits. Therefore, you can concentrate on what's more readable for the maintainers of the code (which could be a future you).
The shortest version would be
public bool IsSomething()
{
return MeetRequirementX() && MeetRequirementY() && MeetRequirementZ();
}
which is fine if it's kind of obvious how these requirements combine into the desired result for IsSomething()
. If that's not obvious, you'd better explain why each requirement is necessary with a comment, and then I'd prefer the following:
public bool IsSomething()
{
// comment explaining why requirement X is necessary
if (!MeetRequirementX()) return false;
// comment explaining why requirement Y is necessary
if (!MeetRequirementY()) return false;
// comment explaining why requirement Z is necessary
return MeetRequirementZ();
}
Or replace the last line with
if (!MeetRequirementZ()) return false;
return true;
if you prefer the symmetry of that.