Just a friendly reminder about using arrays in boolean conditions
user1234
user1234 at 12.de
Mon Nov 18 16:42:51 UTC 2024
On Monday, 18 November 2024 at 15:39:38 UTC, Dom DiSc wrote:
> On Monday, 18 November 2024 at 12:24:01 UTC, user1234 wrote:
>>> ```d
>>> void v(string s)
>>> {
>>> if (s.length) writeln("case length :`", s, "`");
>>> else if (s is null) writeln("case null :`", s, "`");
>>> else writeln("case not null but no
>>> length:`", s, "`");
>>> }
>
> One should always first check for null and then for length.
> This should be immediately clear, as asking for a length
> doesn't make sense if something is null.
No! check the length and only the length ;)
More information about the Digitalmars-d
mailing list