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

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 🙂

  • 0 0 Answers
  • 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

Ask A Question

Stats

  • Questions 76k
  • Answers 77k
  • 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 May want to try installing Windows Media Services on your… May 11, 2026 at 3:16 pm
  • added an answer Check out this excellent resource: SSW Rules to Better SQL… May 11, 2026 at 3:16 pm
  • added an answer There is a site that provides patches for and arm… May 11, 2026 at 3:16 pm

Related Questions

I have landed a side project where a company wants me to develop a
For my Programming 102 class we are asked to deliver C code that compiles
I am trying the FDT editor on a project that previously ran successfully in
I'm new to LaTeX and I must say that I am really struggling with

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.