Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4246380
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T03:57:56+00:00 2026-05-21T03:57:56+00:00

Every day I always come across this dilemma – is it best practice to

  • 0

Every day I always come across this dilemma – is it best practice to check for an undesired state at the start of a function and return straight away or, is it best practice to check for a desired condition and continue else return false.

I understand that there wont be a 1 fits all solution and that this is really a style issue but I am just interested in what other developers would typically do.

I always find my self being indecisive every time this situation comes up.

As an example (coded in php):

Check for the undesired condition first…

function myFunction($myVal)
{
    if ($myVal != 'desiredVal') {
        return false;
    }

    //Continue here with main function code

    return true;
}

Or, check for the desired condition first…

function myFunction($myVal)
{
    if ($myVal == 'desiredVal') {
        //continue here with main function code

        return true;
    }

    return false;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T03:57:57+00:00Added an answer on May 21, 2026 at 3:57 am

    It’s largely a matter of style and both are correct. I find error checking at the top followed by the main method functionality to be cleaner and easier to follow.

    The best advice would be to pick a style and be consistent with it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My university's website always crashes every day at this time of day and it
I have a table that someone update this table every day. I would like
I have a bash script runned every day via cron. In this bash I
Something that has always puzzled me, and still does to this day, is why
I see questions every day asking how to parse or extract something from some
I'm using VS2010 every day, and haven't noticed it before. There is too many
I do upload several files every day and about half of them are successful.
I am working with Ruby every day, but i have an issue in Python.
We have a batch job that runs every day and copies a file to
I want to get the data every day within one year backward but I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.