www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Re: Kill implicit joining of adjacent strings

reply Gary Whatmore <no spam.sp> writes:
Yao G. Wrote:

 On Wed, 10 Nov 2010 20:34:07 -0600, bearophile <bearophileHUGS 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.
 
 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.
 
 Despite Walter seems to ignore C#, C# is a very well designed language,  
 polished, and indeed it refuses automatic joining of adjacent strings:
 [...]
 This is one of the about twenty little/tiny changes I am waiting for D.

Maybe you should switch to C# :)

Or Java.
 
 So please kill automatic joining of adjacent strings in D with fire.

No.

votes++
Nov 11 2010
next sibling parent reply "Steven Schveighoffer" <schveiguy yahoo.com> writes:
On Thu, 11 Nov 2010 08:26:40 -0500, Gary Whatmore <no spam.sp> wrote:

 Yao G. Wrote:

 On Wed, 10 Nov 2010 20:34:07 -0600, bearophile  
 <bearophileHUGS 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  

 joining of strings, the ~, and D strings are allowed to span  

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
Nov 11 2010
parent Gary Whatmore <no spam.sp> writes:
Steven Schveighoffer Wrote:

 On Thu, 11 Nov 2010 08:26:40 -0500, Gary Whatmore <no spam.sp> wrote:
 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.

Good point. I got it now.
Nov 11 2010
prev sibling parent Walter Bright <newshound2 digitalmars.com> writes:
Gary Whatmore wrote:
 Multiline strings have traditionally required stupid hacks.

Yeah, I always hated that. Why couldn't I just insert some multiline text and just put it in quotes? Naw, I have to laboriously quote each line separately. Ridiculous.
Nov 11 2010