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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T05:14:15+00:00 2026-06-03T05:14:15+00:00

I have been writing: if(Class.HasSomething() == true/false) { // do somthing } else {

  • 0

I have been writing:

if(Class.HasSomething() == true/false) 
{
  // do somthing
}
else
{
  // do something else
}

but I’ve also seen people that do the opposite:

if(true/false == Class.HasSomething())
{
  // do somthing
}
else
{
  // do something else
}

Is there any advantage in doing one or the other in terms of performance and speed? I’m NOT talking about coding style here.

  • 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. Editorial Team
    Editorial Team
    2026-06-03T05:14:16+00:00Added an answer on June 3, 2026 at 5:14 am

    The second example is what I’ve heard called “Yoda conditions”; “False, this method’s return value must be”. It’s not the way you’d say it in English and so among English-speaking programmers it’s generally looked down on.

    Performance-wise, there’s really no difference. The first example is generally better grammatically (and thus for readability), but given the name of your method the “grammar” involved (and the fact you’re comparing bool to bool) would make the equality check redundant anyway. So, for a true statement, I would simply write:

    if(Class.HasSomething()) 
    {
      // do somthing
    }
    else
    {
      // do something else
    }
    

    This would be incrementally faster, as the if() block basically has a built-in equality comparison, so if you code if(Class.HasSomething() == true) the CLR will evaluate if((Class.HasSomething() == true) == true). But, we’re talking a gain of maybe a few clocks here (not milliseconds, not ticks, but clocks; the ones that happen 2 billion times a second in modern processors).

    For a false condition, it’s a toss-up between using the not operator: if(!Class.HasSomething()) and using a comparison to false: if(Class.HasSomething() == false). The first is more concise, but it can be easy to miss that little exclamation point in a complex expression (especially since it occurs before the entire expression) and so I’d consider equating with false to ensure that the code is readable.

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

Sidebar

Related Questions

I have been writing several class templates that contain nested iterator classes, for which
I have been writing a PHP class that is exactly 450 lines long and
I have been writing DLL on C++, that will be use in C#. DLL
I have been writing a small java application (my first!), that does only a
I have been writing some code that creates a generic blog. Its features are
i know this is incredibly easy but I have been writing and rewriting this
Hey guys, I have a problem with a code that I've been writing. I
I have been tasked with a project at work of writing a class to
I've been learning Ruby for a class and have been writing a sample game.
So I am writing a class that plays the card game war. I have

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.