Comment #0 by andrej.mitrovich — 2016-10-07T19:37:44Z
In the upcoming version of DMD implicit concatenation of strings is deprecated.
However, simply adding ~ may not lead to the same semantics as before. Observe:
-----
import std.stdio;
import std.string;
void main ( )
{
string a = "some %s format "
"string".format("nice");
writeln(a); // ok
string b = "some %s format " ~
"string".format("nice"); // exception thrown
writeln(b);
}
-----
In the second example format() is called before the two strings are concatenated.
Comment #1 by issues.dlang — 2016-10-07T22:52:12Z
Okay. What's the bug? There has been talk of making it so that expressions are always evaluated left-to-right, but AFAIK, it's still the case the order of evalutation is undefined. So, ~ is behaving perfectly normally. You might as well complain that
import std.stdio;
int foo(int i, int j)
{
return i * j;
}
void main ( )
{
writeln(42 + 10 * 19);
writeln((42 + 10) * 19);
writeln(42 + 10.foo(19));
}
prints
232
988
232
instead of
232
988
988
With the implicit string concatenation, it basically treated the strings as one giant string, and concatenated them at compile time. ~ on the other hand would only be compile time if it's optimized to be that way. So, they've never had the same semantics, and it doesn't make sense for them to.
So, while I grant you that this shows that simply replacing an implicit string concatenation with an explicit one is not necessarily the correct fix for code that uses implicit string concatenation, I don't see how that's a bug.
Comment #2 by andrej.mitrovich — 2016-10-07T23:01:56Z
Right, but I think we should add this note to the changelog. I'm changing the issue to be an enhancement.
Comment #3 by issues.dlang — 2016-10-08T07:24:31Z
I totally agree that this should be put in the changelog, since the difference is not necessarily, immediately obvious, but I don't think that there's actually a bug here or that there's a problem with ~.
Comment #4 by ricejm01 — 2016-11-25T02:51:59Z
I actually have to complain about this whole thing. In C/C++, Java, C# and virtually every programming language based on the C syntax allows for implicit string concatenation.
Allowing this to be depreciated you are making the D language harder to use.
the rationale for the reasoning for why all of sudden we have to start using ~ to break up long strings so that the code is readable is quite frankly Bullshit!
Case in point.
this:
string[] names =
[
"Anna",
"Michael"
"Emma",
"David"
];
// The content of arr is [ "Anna", "MichaelEmma", "David" ]
Vs.
string aReallyLongString = "this is a really long string that will"
"not look good on the page if it put on"
" a single line";
There is a huge difference between Array assignment and single string assignment. How about you revert the changes in 2.072 and re-implement to fix the actual problem, which solely with array assignment and look for '[' ']' characters to not allow implicit string concatenation.
At this point 2.072 is not usable, and I would appreciate not having to fix ~20,000 lines of code to add '~' everywhere. Not to mention you just broke almost every dub library I use as well.
Comment #5 by robert.schadek — 2024-12-15T15:23:56Z