www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Implicit concatenation of adjacent string literals

reply Cecil Ward <cecil cecilward.com> writes:
This is not supported in D and to concatenate string literals an 
explicit ‘~’ operator is required. I’m in two minds as to whether 
that is a good thing, and am not settling either way. I would be 
interested to know what the arguments were for and against, when 
this design aspect was chosen.
Jun 25 2023
parent reply Richard (Rikki) Andrew Cattermole <rikki cattermole.co.nz> writes:
This use to work.

It was removed a few years ago.
Jun 25 2023
parent reply Cecil Ward <cecil cecilward.com> writes:
On Sunday, 25 June 2023 at 21:22:49 UTC, Richard (Rikki) Andrew 
Cattermole wrote:
 This use to work.

 It was removed a few years ago.
I think so too. I recently had to rework a lot of old code because of it, a real nuisance. Was it thought that null concat was dangerous somehow? A recipe for potential for some kind of mistakes? I presume that reinstating it would be safe enough? If there’s any reason to.
Jun 25 2023
parent reply Dave P. <dave287091 gmail.com> writes:
On Sunday, 25 June 2023 at 21:30:52 UTC, Cecil Ward wrote:
 On Sunday, 25 June 2023 at 21:22:49 UTC, Richard (Rikki) Andrew 
 Cattermole wrote:
 This use to work.

 It was removed a few years ago.
I think so too. I recently had to rework a lot of old code because of it, a real nuisance. Was it thought that null concat was dangerous somehow? A recipe for potential for some kind of mistakes? I presume that reinstating it would be safe enough? If there’s any reason to.
It’s easy to make this mistake: ```d const x = [ "foo" "bar", "baz" ]; ``` `x` only has 2 elements, when it looks like it has 3.
Jun 25 2023
parent reply Cecil Ward <cecil cecilward.com> writes:
On Sunday, 25 June 2023 at 21:39:13 UTC, Dave P. wrote:
 On Sunday, 25 June 2023 at 21:30:52 UTC, Cecil Ward wrote:
 On Sunday, 25 June 2023 at 21:22:49 UTC, Richard (Rikki) 
 Andrew Cattermole wrote:
 This use to work.

 It was removed a few years ago.
I think so too. I recently had to rework a lot of old code because of it, a real nuisance. Was it thought that null concat was dangerous somehow? A recipe for potential for some kind of mistakes? I presume that reinstating it would be safe enough? If there’s any reason to.
It’s easy to make this mistake: ```d const x = [ "foo" "bar", "baz" ]; ``` `x` only has 2 elements, when it looks like it has 3.
An excellent point. I now fall in with the new status quo. :-)
Jun 25 2023
parent Mathias LANG <geod24 gmail.com> writes:
On Sunday, 25 June 2023 at 21:47:01 UTC, Cecil Ward wrote:
 `x` only has 2 elements, when it looks like it has 3.
An excellent point. I now fall in with the new status quo. :-)
And it's exactly the reasoning behind the deprecation. You can find it in the changelog for 2.072, where this deprecation was introduced: https://dlang.org/changelog/2.072.0.html#deprecated_implicit_cat Note that using the concat operator gives you exactly the same behavior: Concatenation happens at compile time, there is no runtime cost / GC allocation.
Jun 25 2023