Recently, while I was reviewing some codes, I saw there were some conditional statements that check for the same condition but written in different ways. Most of these statements were written with common sense without using any mathematical analysis, since those are too simple to go for a more formal approach. The two identical conditional statements that has been written in different ways are given below.

01)

if ($comment['deleted'] == '1' || $comment['approved'] == '0') {

unset($conversationsArray[$key]);

} else {

++$count;

}

02)

if ($comment['deleted'] == '0' && $comment['approved'] == '1') {

++$count;

} else {

unset($conversationsArray[$key]);

}

Obviously, the above lines say that the inverse of the first condition is equals to the second condition and vice versa. That is...

($comment['deleted'] == '1' || $comment['approved'] == '0') "equals to" !($comment['deleted'] == '0' && $comment['approved'] == '1') .

That means simply in this case...

(true || false) ==> !(false && true)

This is an one real life example to prove the theory called "De Morgan's Law" in Pure Mathematics. Theories like these can be used to improve the source codes in many ways. In the cases like above, one can write more consistent and efficient codes with the knowledge of these theories.

On the other hand, in the early ages, if the students are aware of the real applications of those theories they will learn those with some more enthusiasm.

http://en.wikipedia.org/wiki/De_Morgan's_law

http://en.wikipedia.org/wiki/Augustus_De_Morgan

01)

if ($comment['deleted'] == '1' || $comment['approved'] == '0') {

unset($conversationsArray[$key]);

} else {

++$count;

}

02)

if ($comment['deleted'] == '0' && $comment['approved'] == '1') {

++$count;

} else {

unset($conversationsArray[$key]);

}

Obviously, the above lines say that the inverse of the first condition is equals to the second condition and vice versa. That is...

($comment['deleted'] == '1' || $comment['approved'] == '0') "equals to" !($comment['deleted'] == '0' && $comment['approved'] == '1') .

That means simply in this case...

(true || false) ==> !(false && true)

This is an one real life example to prove the theory called "De Morgan's Law" in Pure Mathematics. Theories like these can be used to improve the source codes in many ways. In the cases like above, one can write more consistent and efficient codes with the knowledge of these theories.

On the other hand, in the early ages, if the students are aware of the real applications of those theories they will learn those with some more enthusiasm.

**More details:**http://en.wikipedia.org/wiki/De_Morgan's_law

http://en.wikipedia.org/wiki/Augustus_De_Morgan

## Comments

vận chuyển