Thread overview
Implicit concatenation of adjacent string literals
Jun 25, 2023
Cecil Ward
Jun 25, 2023
Cecil Ward
Jun 25, 2023
Dave P.
Jun 25, 2023
Cecil Ward
Jun 25, 2023
Mathias LANG
June 25, 2023
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.
June 25, 2023
This use to work.

It was removed a few years ago.
June 25, 2023
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.
June 25, 2023

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:

const x = [
     "foo"
     "bar",
     "baz"
];

x only has 2 elements, when it looks like it has 3.

June 25, 2023
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. :-)
June 25, 2023
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.