On Tuesday, 24 September 2019 at 00:29:05 UTC, Vladimir Panteleev wrote:
On Monday, 23 September 2019 at 23:22:14 UTC, Brett wrote:
I guess you are probably right... I was thinking that it would compare up to a null terminator. Seems kinda buggy... maybe the compiler needs to give a warning? After all, compared a fixed size array with a dynamic array then will almost always fail since it is unlikely the sizes will match...

...rather than failing silently.

It might still be useful for generic code, so a compiler warning would probably not be suitable. However, it might be a good idea for a linter such as Dscanner, which, unlike the compiler, sees types as they are written in the code, not as they are calculated through metaprogramming.

The only issue is that buggy dynamic code can result if someone compares the two and it will fail silently. It could be quite complex bug that destroys the space station. Warnings never hurt and with the ability to disable specific ones one can bypass such issues. (disable then enable)

But if it behaves in a non-standard way based on some somewhat arbitrary limitation(fixed arrays are only arbitrary because of the limitations of computers) then it's going to bit people and the more D is used the more people that will get bitten.

If I convert a static array to a string, I want the "string" portion of the array. Strings are special, they are meant to have specific representation. Strings do not have 0 characters in them normally.

So upon conversion, to!string would detect this and either error out or stop the conversion at that point. The only time one would want to retain junk values is for displaying bytes, but then one should just convert to a byte or char array.

But of course those people that have be using to!string to convert arbitrary bytes will have their code broken... but I imagine few have done this(there really is no point).

The same thing should happen when converting anything to a string, it should detect malformed strings and either error or terminate(if zero terminated).

This makes for a more consistent ecosystem.

if, for example, I stick null terminated strings in a buffer then to!string will automatically recover them(the first one, assuming one each time).

There is probably no win-win situation though and so I suggest just a warning when converting arrays to strings.





Reply via email to