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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T23:22:21+00:00 2026-05-12T23:22:21+00:00

I recently read in Code Complete that the recommended way of handling expressions that

  • 0

I recently read in Code Complete that the recommended way of handling expressions that involve numbers is to order them like a number line.

The book has 2 examples:

if ( (MIN_ELEMENTS <= i) && (i <= MAX_ELEMENTS) )

if ( (i < MIN_ELEMENTS) || (MAX_ELEMENTS < i ) )

With the first example showing that i is between the min and max elements, and the second example being that i falls outside the range between the elements.

I’ve been trying to adopt it, and I’m not sure if it’s just the way I think, but I don’t think it’s making code any clearer.

Example:

 if (m_Health > BOSS_HALF_HEALTH) // The way it was

 if (BOSS_HALF_HEALTH <= m_Health) // The "number line" method

Is it just me, or does the number line method seem less clear? What are your thoughts regarding this practice?

It’s also odd that he mentions putting constants on the left side of comparisons contradicts the number-line-method, but here it seems that the number line method leads to putting the constant on the left side.

  • 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-05-12T23:22:21+00:00Added an answer on May 12, 2026 at 11:22 pm

    I think the original motivation comes from having more than one comparison in the same logical expression. Both the quoted examples are comparing between both a lower and upper bound of a range. This ordering method may have value in those situations.

    However, I don’t think it’s necessarily applicable if you’re testing a single condition, such as m_Health > BOSS_HALF_HEALTH. In that case, the comparison you’re making is whether something (a variable) is greater than something else. That’s perfectly logical and doesn’t need to be ordered in any particular way.

    If you always ordered your comparisons in a “number line” way, you would never even need the > or >= comparison operators. They exist for good reasons.

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

Sidebar

Related Questions

I recently read through Code Complete, and it recommends that I create a project
Microsoft has recently broken our longtime (and officially recommended by them) code to read
I recently read about a new Google-code hosted (open source) project from Google that
I recently read the discussion https://stackoverflow.com/questions/62617/whats-the-best-way-to-separate-php-code-and-html I am facing a similar dilemma. Currently working
I have recently read Mike McShaffry's Game Coding Complete and noticed the code style
I've recently written a piece of code to read some data from a file,
I recently read the the following SO question. What's the best way to store
I recently read in a presentation on Scribd that Facebook had benchmarked a variety
I recently read that getters/setters are evil and I have to say it makes
I recently read in a magazine that there is a new commercial developer tool

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.