Kill implicit joining of adjacent strings
Steven Schveighoffer
schveiguy at yahoo.com
Thu Nov 11 05:44:37 PST 2010
On Thu, 11 Nov 2010 08:26:40 -0500, Gary Whatmore <no at spam.sp> wrote:
> Yao G. Wrote:
>
>> On Wed, 10 Nov 2010 20:34:07 -0600, bearophile
>> <bearophileHUGS at lycos.com>
>> 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.
>>
>> Stop blaming the compiler for your own carelessness.
>
> I fully agree with this. It's odd to see only few people opposing this,
> because the feature has no merit. If the language needs to be overly
> verbose in every turn, bearophile could go and use Java instead.
The "feature" of concatenating two strings together automatically without
any operator has no merit. In C it was important because C does not have
any other way to concatenate multiple strings together at compile-time.
With the way the preprocessor works, it would be very difficult to
concatenate string literals with macros. But we don't have a preprocessor
in D and D *does* have constant folding with the ~ operator.
This is a no brainer -- we need to kill auto string concatenation. It
serves no purpose, there is already a clear, concise, unambiguous
alternative that fits exactly into the language grammar.
It's like the operator precedence of logical and comparison operators was
a carryover from the B language. I'm sooo glad we got rid of that.
>> > 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.
>>
>> I find it useful, and I like it. I like to break long strings into
>> smaller
>> ones
>> and put each one in one line. I know that you can do that using one
>> single
>> string, but
>> some syntax hightlighters don't like it that way.
>
> Multiline strings have traditionally required stupid hacks. D might be
> the only string oriented language with so many useful string literals.
> Very useful in string processing.
In this case, it's not a hack, it fits precisely within the definition of
the language. It's like saying:
1 +
2
is a 'hack' to get multi-line addition working. How many times have you
written:
if((condition1 && condition2) ||
condition3 ||
condition4 ||
...)
To keep your sanity when writing complex if statements? Have you ever
felt that adding those pesky || at the end of each line was a 'hack'?
This is exactly the same thing.
-Steve
More information about the Digitalmars-d
mailing list