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?
Edit: 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.