On Friday, 21 August 2015 at 11:34:42 UTC, Marc Schütz wrote:
On Thursday, 20 August 2015 at 19:41:44 UTC, Jonathan M Davis
wrote:
On Thursday, 20 August 2015 at 17:50:11 UTC, Steven
Schveighoffer wrote:
if(arr != null)
Definitely don't do that. IMHO, "== null and "!= null" should
be illegal. If you really want to check for null, then you
need to use "is null" or "!is null", whereas if you want to
check that an array is empty, check its length or call empty.
By using "== null" or "!= null", you tend to give the false
impression that you're checking whether the object or array is
null - which is not what you're actually doing.
I disagree. `is null` is the one that should be illegal. `is`
is supposed to do a bitwise comparison, but `null` is usually
just a pointer/reference, while a slice consists of both a
reference and a length. Which of those are compared?
is, as its name says, is an identity check. It check that 2 thing
ARE the same thing.
==, on the other hand, is a value check. It check if 2 thing have
the same value, regardless if they are the same or not.