Re: Empty string vs null

2020-02-04 Thread mark via Digitalmars-d-learn
Thanks for that thorough and careful explanation. Since I'm trying to learn to write D in good style and want my code to be reliable and maintainable, I've now switched to using "" rather than null.

Re: Empty string vs null

2020-02-04 Thread Jonathan M Davis via Digitalmars-d-learn
On Tuesday, February 4, 2020 12:33:42 AM MST mark via Digitalmars-d-learn wrote: > I have just discovered that D seems to treat empty and null > strings as the same thing: > > // test.d > import std.stdio; > import std.string; > void main() > { > string x = null; > writeln("x = \"",

Re: Empty string vs null

2020-02-03 Thread JN via Digitalmars-d-learn
On Tuesday, 4 February 2020 at 07:44:08 UTC, mark wrote: Just found this post by Mark Parker that explains: https://forum.dlang.org/post/gvveit$10i5$1...@digitalmars.com I recommend using Nullable from https://dlang.org/phobos/std_typecons.html#Nullable if you want to explicitly allow a non-v

Re: Empty string vs null

2020-02-03 Thread mark via Digitalmars-d-learn
Just found this post by Mark Parker that explains: https://forum.dlang.org/post/gvveit$10i5$1...@digitalmars.com // test.d import std.stdio; import std.string; void main() { report(null, "null"); report(""); report("x"); } void report(const string x, const string name=null) { w

Empty string vs null

2020-02-03 Thread mark via Digitalmars-d-learn
I have just discovered that D seems to treat empty and null strings as the same thing: // test.d import std.stdio; import std.string; void main() { string x = null; writeln("x = \"", x, "\""); writeln("null = ", x == null); writeln("\"\"= ", x == ""); writeln("empty