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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T14:29:46+00:00 2026-05-10T14:29:46+00:00

boolean a = false, b = true; if ( a && b ) {

  • 0
boolean a = false, b = true; if ( a && b ) { ... }; 

In most languages, b will not get evaluated because a is false so a && b cannot be true. My question is, wouldn’t short circuiting be slower in terms of architecture? In a pipeline, do you just stall while waiting to get the result of a to determine if b should be evaluated or not? Would it be better to do nested ifs instead? Does that even help?

Also, does anyone know what short-circuit evaluation is typically called? This question arose after I found out that my programming friend had never heard of short-circuit evaluation and stated that it is not common, nor found in many languages, and is inefficient in pipeline. I am not certain about the last one, so asking you folks!

Okay, I think a different example to perhaps explain where my friend might be coming from. He believes that since evaluating a statement like the following in parallel:

(a) if ( ( a != null ) && ( a.equals(b) ) ) { ... } 

will crash the system, an architecture that doesn’t have short-circuiting (and thereby not allowing statements like the above) would be faster in processing statements like these:

(b) if ( ( a == 4 ) && ( b == 5 ) ) 

since if it couldn’t do (a) in parallel, it can’t do (b) in parallel. In this case, a language that allows short-circuiting is slower than one that does not.

I don’t know if that’s true or not.

Thanks

  • 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-10T14:29:47+00:00Added an answer on May 10, 2026 at 2:29 pm

    Short-circuiting boolean expressions are exactly equivalent to some set of nested ifs, so are as efficient as that would be.

    If b doesn’t have side-effects, it can still be executed in parallel with a (for any value of ‘in parallel’, including pipelining).

    If b has side effects which the CPU architecture can’t cancel when branch prediction fails then yes, this might require delays which wouldn’t be there if both sides were always evaluated. So it’s something to look at if you do ever find that short-circuiting operators are creating a performance bottleneck in your code, but not worth worrying about otherwise.

    But short-circuiting is used for control flow as much as to save unnecessary work. It’s common among languages I’ve used, for example the Perl idiom:

    open($filename) or die('couldn't open file'); 

    the shell idiom:

    do_something || echo 'that failed' 

    or the C/C++/Java/etc idiom:

    if ((obj != 0) && (obj->ready)) { do_something; } // not -> in Java of course. 

    In all these cases you need short-circuiting, so that the RHS is only evaluated if the LHS dictates that it should be. In such cases there’s no point comparing performance with alternative code that’s wrong!

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

Sidebar

Ask A Question

Stats

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

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

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

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

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer To solve this problem, I ended up making a flat… May 12, 2026 at 7:20 pm
  • Editorial Team
    Editorial Team added an answer The portion after your file name /index.php is called the… May 12, 2026 at 7:20 pm
  • Editorial Team
    Editorial Team added an answer The HttpFox plugin for Firefox works pretty well for this… May 12, 2026 at 7:20 pm

Related Questions

I know about Arrays.deepEquals(Object[], Object[]) but this doesn't work for primitive types (due limitations
I'm trying to override the equality (==) operator in C# to handle comparing any
Is there a way to tell the php complier that I want a specific
This originally was a problem I ran into at work, but is now something

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.