Skip to main content
Post Closed as "Not suitable for this site" by t3chb0t, Heslacher, user34073, BCdotWEB, user73941
edited body
Source Link
dafie
  • 299
  • 2
  • 8

Lets say I have simple IsSomething() method which checks, if object meets few requirements. Which approach is better?

public bool IsSomething()
{
    if (!MeetRequirementX()) return false;
    if (!MeetRequirementY()) return false;
    if (!MeetRequirementZ()) return false;
    
    return true;
}

Or

public bool IsSomething()
{
    if (MeetRequirementX() &&
    if   MeetRequirementY() &&
    if   MeetRequirementZ())
        return true;
    
    return false;
}

Lets say I have simple IsSomething() method which checks, if object meets few requirements. Which approach is better?

public bool IsSomething()
{
    if (!MeetRequirementX()) return false;
    if (!MeetRequirementY()) return false;
    if (!MeetRequirementZ()) return false;
    
    return true;
}

Or

public bool IsSomething()
{
    if (MeetRequirementX() &&
    if MeetRequirementY() &&
    if MeetRequirementZ())
        return true;
    
    return false;
}

Lets say I have simple IsSomething() method which checks, if object meets few requirements. Which approach is better?

public bool IsSomething()
{
    if (!MeetRequirementX()) return false;
    if (!MeetRequirementY()) return false;
    if (!MeetRequirementZ()) return false;
    
    return true;
}

Or

public bool IsSomething()
{
    if (MeetRequirementX() &&
       MeetRequirementY() &&
       MeetRequirementZ())
        return true;
    
    return false;
}
Source Link
dafie
  • 299
  • 2
  • 8

Should method return default true, or false when meeting requirements

Lets say I have simple IsSomething() method which checks, if object meets few requirements. Which approach is better?

public bool IsSomething()
{
    if (!MeetRequirementX()) return false;
    if (!MeetRequirementY()) return false;
    if (!MeetRequirementZ()) return false;
    
    return true;
}

Or

public bool IsSomething()
{
    if (MeetRequirementX() &&
    if MeetRequirementY() &&
    if MeetRequirementZ())
        return true;
    
    return false;
}