arrays: if(null == [ ])
Jonathan M Davis
jmdavisProg at gmx.com
Wed May 16 16:08:49 PDT 2012
On Wednesday, May 16, 2012 09:18:38 Steven Schveighoffer wrote:
> but I still think we should discourage using null as a
> sentinel, it leads to confusing code.
If null were actually properly differentiated from empty, then this wouldn't be
a problem, but it's not. It _should_ be possible to treat null as a sentinel.
The fact that it causes issues is a major flaw in the language IMHO. But given
that flaw, it does very quickly become error-prone to use null as a sentinel.
In general, I'd say that the only reasonable place to do so is when returning
an array (and especially a string) from a function. The return value can then
be immeditely checked with is null before it has the chance to have something
happen to it which could cause it to be empty but non-null.
- Jonathan M Davis
More information about the Digitalmars-d
mailing list