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 85477
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T22:05:44+00:00 2026-05-10T22:05:44+00:00

I often run into code that has to perform lots of checks and ends

  • 0

I often run into code that has to perform lots of checks and ends up being indented at least five or six levels before really doing anything. I am wondering what alternatives exist.

Below I’ve posted an example of what I’m talking about (which isn’t actual production code, just something I came up with off the top of my head).

public String myFunc(SomeClass input) {     Object output = null;      if(input != null)     {         SomeClass2 obj2 = input.getSomeClass2();         if(obj2 != null)         {             SomeClass3 obj3 = obj2.getSomeClass3();             if(obj3 != null && !BAD_OBJECT.equals(obj3.getSomeProperty()))             {                 SomeClass4 = obj3.getSomeClass4();                 if(obj4 != null)                 {                     int myVal = obj4.getSomeValue();                     if(BAD_VALUE != myVal)                     {                         String message = this.getMessage(myVal);                         if(MIN_VALUE <= message.length() &&                            message.length() <= MAX_VALUE)                         {                             //now actually do stuff!                             message = result_of_stuff_actually_done;                         }                     }                 }             }         }     }     return output; } 
  • 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-10T22:05:44+00:00Added an answer on May 10, 2026 at 10:05 pm

    See Flattening Arrow Code for help.

    1. Replace conditions with guard clauses.
    2. Decompose conditional blocks into seperate functions.
    3. Convert negative checks into positive checks.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I often run into the problem that I have one stream full of data
Something that I often run into with my users is their desire to aquire
One of the problems I often run into, is that I will include '
I often run into the following problem. I work on some changes to a
I'm working on a webapp, and every so often we run into situations where
I run into this quite often where a new page is supposedly tested and
I seem to run into this very often. I need to build a Hash
I have two scripts that often need to be run with the same parameter:
In my Java code, I occasionally run into situations where I have to catch
I'm developing Scala code using Eclipse, often when I run tests I get this

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.