null == "" is true?

H. S. Teoh hsteoh at qfbox.info
Tue Jul 12 20:14:46 UTC 2022


On Tue, Jul 12, 2022 at 07:55:46PM +0000, ag0aep6g via Digitalmars-d-learn wrote:
> On Tuesday, 12 July 2022 at 19:02:01 UTC, user1234 wrote:
> > On Tuesday, 12 July 2022 at 16:40:38 UTC, H. S. Teoh wrote:
> [...]
> > > Do not rely on this, however;
> > 
> > Absolutely. I'd like to add: especially as default parameter value
> > that's an array. Never use null. use `[]` (empty array literal).
> 
> Just to be clear: `[]` and `null` are the exact same thing (null
> pointer, zero length). The reason to prefer `[]` over `null` is purely
> for readability. The meaning is exactly the same.

Pedantically, no, they're not the same. You can assign null to a
pointer, but you can't assign [] to a pointer. `null` is a supertype of
`[]`.

But probably nobody actually cares about this distinction. :-D


T

-- 
By understanding a machine-oriented language, the programmer will tend to use a much more efficient method; it is much closer to reality. -- D. Knuth


More information about the Digitalmars-d-learn mailing list