code readability

Which method is easier to read?

name = 'Jack'
age = 45
# 1
print('Hello, %s. You are %s.' % (name, age))
# 2
print(f'Hello, {name}. You are {age}.')

Code readability is more important than micro-optimization because in most part of cases micro-optimization does not worth it.

In general, readability is more important than cleverness or brevity.

isset( $var ) || $var = some_function();

Although the above line is clever, it takes a while to grok if you're not familiar with it. So, just write it like this:

if ( ! isset( $var ) ) {
    $var = some_function();
if ($a OR $b) {} // 'OR' better than '||'
if ($a AND $b) {} // 'AND' better than '&&'

Leave a Reply

Your email address will not be published. Required fields are marked *