Is implicit string literal concatenation a good thing?
Bill Baxter
wbaxter at gmail.com
Sun Feb 22 09:51:18 PST 2009
On Sun, Feb 22, 2009 at 11:12 PM, Denis Koroskin <2korden at gmail.com> wrote:
> On Sun, 22 Feb 2009 16:50:51 +0300, Christopher Wright <dhasenan at gmail.com>
> wrote:
>
>> Brad Roberts wrote:
>>>
>>> Back in c and c++, with it's pre-processor, merging adjacent string
>>> literals is very handy. In D, it's only marginally so, but not
>>> completely useless. It can still be used to break a really long string
>>> literal into parts. There's other string boundary tokens in D which
>>> might well provide viable alternatives.
>>
>> In C and C++, there is no way to catenate strings at compile time. The
>> only way to catenate strings is with strcat. That places the additional
>> burden on programmers that they have to include string.h. For that reason,
>> it makes sense to catenate adjacent string literals.
>>
>> In D, there's a compile time catenation operator that doesn't require
>> libraries. So the catenation by association saves you only one character.
>> I'd say that's useless.
>
> I agree.
I use this feature pretty frequently to break up long strings.
I think I didn't use ~ for that because it makes me think an
allocation might happen when it doesn't need to.
But after seeing the discussion here I'd be happy to switch to using
"a"~"b" as long as it's guaranteed by the language that such strings
will be concatenated at compile time. (I think the is the case now,
right?)
--bb
More information about the Digitalmars-d
mailing list