Code smell - READIBILITY

In my opinion readability is the most important attribute of code.

Good code should be easy to read.
That makes code easy to understand, maintain and REUSE.

 

Ignore the meaning of the code but look at the layout... What would you prefer?

  if (myTrueValue) myFirstTempVariable = 1;
  if (!myTestStatement) mySecondTempVariable = 0;
  if (mySecondTestStatement) myThirdTempVariable = 0;
  if (!myFourthTestStatement) mySecondTempVariable = 1;
Hard to read

 

  if (myTrueValue == true) myFirstTempVariable = 1;
  if (myTestStatement == false) mySecondTempVariable = 0;
  if (mySecondTestStatement == true) myThirdTempVariable = 0;
  if (myFourthTestStatement == false) mySecondTempVariable = 1;
GOOD: Already much easier to read

 

  if (true == myTrueValue) myFirstTempVariable = 1;
  if (false == myTestStatement) mySecondTempVariable = 0;
  if (true == mySecondTestStatement) myThirdTempVariable = 0;
  if (false == myFourthTestStatement) mySecondTempVariable = 1;
GOOD: What about this? Already much easier to read??

Latest Posts

Popular Posts