readability

Christian Harms's picture

basic rules for code readability and the if statement

Some reader knows my preference for programming languages like python or javascript. One reason is the readability (yes, this is possible with many languages except brainfuck or whitespace). Once we write some lines of code, but other developer has to read the lines of code several times while code reviews, debugging or refactoring.

Code should be readable like your normal language. I will start with a funny condition.

  1. if ( !notOk != false ) {
  2.   userObj.ask();
  3. }

This is only confusing and you will never formulate this expression in a natural language. With several steps this term can be simply resolved:

  • ( !notOk != false )
  • ( !notOk == true )
  • ( !notOk)
  • now you should rethink the variable name: isOk = !notOk

And the result is more readable:Read more

Syndicate content