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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T17:58:50+00:00 2026-05-10T17:58:50+00:00

I am new to programming, and am wondering if there is a correct way

  • 0

I am new to programming, and am wondering if there is a correct way to order your control structure logic.

It seems more natural to check for the most likely case first, but I have the feeling that some control structures won’t work unless they check everything that’s false to arrive at something that’s true (logical deduction?)

It would be hard to adapt to this ‘negative’ view, I prefer a more positive outlook, presuming everything is true 🙂

  • 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-10T17:58:50+00:00Added an answer on May 10, 2026 at 5:58 pm

    In most situations, readability is more important than execution speed. I therefore try to optimize for ease of understanding, by using the following approach:

    All ‘assertion’ checks are done up front. this guarantees that all erroneous cases are dealt with at the very start. this is especially important for null-pointer-checks, e.g.

         if(arg == null){        throw new IllegalArgumentException();  // harsh (correct)     }     // or      if(arg == null){         arg = '';  // forgiving (lazy)     } 

    Next, i try to check for 1 condition only in each if-statement. instead of

         if(condition1 && condition2) {         ...     } else {         ...     } 

    i generally prefer

         if(condition1) {         if(condition2) {             ...         } else {             ...         }     } else {         ...     } 

    This approach is easier for setting breakpoints, and it makes the logic more obvous.

    I avoid negations; instead of

         if(! condition) {         ...a...     } else {         ...b...     } 

    things are better rearranged to

         if(condition) {         ...b...     } else {         ...a...     } 

    Finally, all methods that return a boolean result should have a ‘positive’ name that indicates what the results means:

         boolean checkSomething(Something x){ ... }     // bad -- whats the result?     boolean isSomethingInvalid(Something x){ ... } // better, but ...     boolean isSomethingValid(Something x){ ... }   // best, no 'mental negation' 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new to cocoa programming but i'm wondering if there is a way to
I am new to programming, I was wondering if there is a way to
I am very new to the whole programming business, and was wondering if there
I am new to C# and .Net programming, but i am wondering if there
I'm quite new to programming, and I was wondering if there is a good
I'm new to using C programming I was wondering if there is a function
I am new to Haskell and I'm wondering if there's a way to output
I'm new to android programming, and I was wondering if there was an event
I'm new to programming for the iPhone and i'm wondering: how extensible are the
I am fairly new to Android programming and was wondering how I can get

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.