Last Updated: November 23, 2016
·
880
· eldadfux

Don't mix comparison (==) with assignment (=)

When using comparisons always put your constants on the left. This practice will help you avoid mixing comparison (==) with assignment (=) and will save you hours of clueless debugging.

Recommended:

if (null == $var) {}

if (15 == $number) {}

Not recommended:

if ($var == null {}

if ($number == 15) {}

Bad (!!):
if ($var = null {}

if ($number = 15) {}

This is something you might find a bit hard to get use to, but at the end should probably pay off.

1 Response
Add your response

It doesn't concern Java. Anyway it's good to place a constant on the left to avoid NPEs.

over 1 year ago ·

Have a fresh tip? Share with Coderwall community!

Post
Post a tip
Did you know?

JavaScript on a page runs with the privileges of that origin. One altered library, tag manager, or snippet can read inputs, change what people see, and call your APIs as the user.

Security insights from Cside