On Saturday, 13 September 2014 at 23:21:09 UTC, David Nadlinger wrote:
On Saturday, 13 September 2014 at 22:41:39 UTC, AsmMan wrote:
D string are actullay C-strings?

No. But string *literals* are guaranteed to be 0-terminated for easier interoperability with C code.

David

ah makes sense.


On Sunday, 14 September 2014 at 12:07:16 UTC, Marc Schütz wrote:
On Sunday, 14 September 2014 at 09:07:26 UTC, Kagamin wrote:
On Sunday, 14 September 2014 at 00:34:56 UTC, WhatMeWorry wrote:
So is one form (Empty strings versus null strings) considered better than the other? Or does it depend on the context?

For all practical purposes they should be equivalent in D code. I suppose the distinction exists because somebody claimed he can make sense of it. Some API may rely on distinction between null and empty string, like XML DOM, though I don't think such interface is very useful.

Also for some reason boolean value of a string is derived from ptr instead of length... meh.

Which makes sense given the distinction exists, IMO. Compare for example with Ruby, where empty strings and `0` integers also evaluate to true, but only `nil` and `false` evaluated to false.

That's why I don't like most of dynamic languages... type system is a mess. I don't like even the fact one can do:

x = "abc";
f(x)
x = 10;
g(x);

and it work

Reply via email to