Kill implicit joining of adjacent strings
Steven Schveighoffer
schveiguy at yahoo.com
Thu Nov 11 04:35:30 PST 2010
On Wed, 10 Nov 2010 21:34:07 -0500, bearophile <bearophileHUGS at lycos.com>
wrote:
> Do you seen anything wrong in this code? It compiles with no errors:
>
> enum string[5] data = ["green", "magenta", "blue" "red", "yellow"];
> static assert(data[4] == "yellow");
> void main() {}
>
>
> Yet that code asserts. it's an excellent example of why a sloppy
> compiler/language sooner or later comes back to bite your ass.
> I've recently had another bug caused by automatic joining of adjacent
> strings. I think this is the 3rd I have found in my D code. This is
> enough.
>
> In C the joining of adjacent strings is sometimes useful, but explicit
> is better than implicit, and D has a short and good operator to perform
> joining of strings, the ~, and D strings are allowed to span multi-lines.
100% agree. Get rid of it. My suggestion is to make auto-concatenation
an error and see how many unintended errors there are in phobos. This
model of testing has helped to explain how features are bug prone in the
past.
-Steve
P.S. WRT bearophile's constant nagging, I agree it's not the best way to
be heard. But if you feel strongly about something, and it's not getting
attention, I don't see another way. Note that if you didn't continuously
nag about stylistic issues that are very subjective, nagging about real
problems like this would carry more weight.
I wrote a very similar post that resulted in the destruction of class ==
null from the language (ironically, I think it could be inserted back into
the language now that object.opEquals is called instead).
More information about the Digitalmars-d
mailing list