Kill implicit joining of adjacent strings

Brad Roberts braddr at puremagic.com
Wed Nov 10 18:56:02 PST 2010


Nagging is one way to accomplish change, but it's sure annoying.  If you feel
the feature is import, you know where to get the source.  Give it a shot.
Contribution of code is oh so much more valuable than a constant stream of "you
should change..."

Repeatedly claiming that Walter ignores 'X' is another way to get a reaction,
but it's also very annoying.  You're far from the only person to pull this card
out.  Do you _honestly_ believe he's that narrow minded or are you just trying
to get enough of a rise out of such claims that he'll drop what he's doing and
focus on your nag-of-the-day?

Sigh.. it get's old, fast.

Back to lurk mode,
Brad

On 11/10/2010 6:34 PM, bearophile 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.
> 
> C code ported to D that doesn't put a ~ just raises a compile time error that's easy to understand and fix. So this doesn't change the meaning of C code, just asks the programmer to improve the code, and the change requires is fully mechanical.
> 
> The compiler need to be able to perform the joining at compile time, so zero run-time overhead is present. The result is the same as before, it's just a syntax change.
> 
> My bug report has more info and a partial patch:
> http://d.puremagic.com/issues/show_bug.cgi?id=3827
> 
> Despite Walter seems to ignore C#, C# is a very well designed language, polished, and indeed it refuses automatic joining of adjacent strings:
> 
> public class Test {
>     public static void Main() {
>         string s = "hello " "world";
>     }
> }
> 
> That C# code gives the error:
> 
> prog.cs(3,35): error CS1525: Unexpected symbol `world'
> Compilation failed: 1 error(s), 0 warnings
> 
> This is one of the about twenty little/tiny changes I am waiting for D.
> 
> So please kill automatic joining of adjacent strings in D with fire.
> 
> Thank you,
> bearophile



More information about the Digitalmars-d mailing list