--- Comment #4 from Steven Schveighoffer <> 2011-07-18 
13:54:46 PDT ---
There is a flaw in your argument, however.  For the coder to have meant they
want to check specifically if the pointer is null, they have to know there is a
difference between null and an "empty but non-null" slice.  If this is the
case, then wouldn't they use is null instead of == null?

Most coders don't even know that an empty slice could have a non-null pointer,
or would even care.  They just know that comparing an empty slice to null
results in true.  Consider that there are very few, if at all, functions which
make a distinction between null and "empty but not null" slices.  So where
exactly does doing == null lead to a problem?

If you want to focus on confusing spots, the two problems I see are:

if(arr is null)



Both of these act *differently* based on whether the pointer is null or not. 
Now that is confusing.

Note that this can be fixed by doing:

if(arr is null) => warn, recommend using if(arr.ptr is null)

if(arr) => should always be false if arr.length == 0

But I think == null is perfectly safe, and 99% of the time exactly what the
writer intended.

Configure issuemail:
------- You are receiving this mail because: -------

Reply via email to