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

  • Home
  • SEARCH
  • 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 99625
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T00:25:24+00:00 2026-05-11T00:25:24+00:00

Ok I want some opinions how I can fix this mess of a method!

  • 0

Ok I want some opinions how I can fix this mess of a method!

It has WAY to many nested ‘if’ statements.

But realize I have to know exactly where the method fails, currently in each of the respective ‘else’ clause I am logging the error (the failed ‘if’ condition’).

Note: ignore any logic behind the things, please focus on the style and structure as I have made all the function names up etc.

Here is the skeleton structure:

   public void MyMethod() {     try    {     bool tryAgain = false;      string filename = DownloadFile();      if( IsFileFormatOk(filename) )     {          blah = GetBlah(filename);          if(blah.ID > 0)         {              if(ImportFile(filename)             {                  string username = GetUserFromFile(filename);                  if(isValidUser(username))                 {                      // few more levels to go                     //                     //                     //                  }                 else                 {                     LogError(filename, ...); // specific to this if statement                     tryAgain = true;                 }               }             else             {                  LogError(filename, ...); // specific to this if statement                 tryAgain = true;             }          }         else         {             LogError(filename, ...); // specific to this if statement             tryAgain = true;         }      }     else     {         LogError(filename, ...); // specific to this if statement         tryAgain = true;     }     }    catch    {    }    finally    {     if(tryAgain)     {         // blah     }    }   } 
  • 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. 2026-05-11T00:25:25+00:00Added an answer on May 11, 2026 at 12:25 am

    I would work on changing your logic so you can return from the method as soon as possible instead of nesting more logic. Fore example:

    //  GOOD if (!file.exists())     return; // Rest of the code  // BAD if (file.exists()){     // Code goes here } return; 

    This may help remove some nesting and make things less complicated.

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

Sidebar

Ask A Question

Stats

  • Questions 70k
  • Answers 70k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer Virtual addresses work fine with Google Analytics. You will see… May 11, 2026 at 12:47 pm
  • added an answer I found a different approach using javascript: Sys.Application.add_init(function(sender, args) {… May 11, 2026 at 12:47 pm
  • added an answer Edit: If you want a free library, try Flot. Emprise… May 11, 2026 at 12:47 pm

Related Questions

Ok so i want to do a prepared insert such as: prepare(INSERT INTO `analyzeditemsdetails`
Ok here's what I'm trying to do I want to write a class that
OK, I want to create a windows shell extention that sits in the file
Ok, so I want to get a webapp running in tomcat (5.5) to run
Ok this is a little complex. I am creating a plugin, and want to
I'm running Vista 64 box, and attempting to setup Joomla using IIS7 (I like
OK I have a mySQL Database that looks something like this ID - an
Ok I give up, I've been trying to write a regexp in ant to

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.