[Issue 3827] New: automatic joining of adjacent strings is bad
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Thu Feb 18 12:40:32 PST 2010
http://d.puremagic.com/issues/show_bug.cgi?id=3827
Summary: automatic joining of adjacent strings is bad
Product: D
Version: 2.040
Platform: All
OS/Version: Windows
Status: NEW
Severity: normal
Priority: P2
Component: DMD
AssignedTo: nobody at puremagic.com
ReportedBy: bearophile_hugs at eml.cc
--- Comment #0 from bearophile_hugs at eml.cc 2010-02-18 12:40:31 PST ---
import std.stdio;
void main() {
string[] a = ["foo", "bar" "baz", "spam"];
writeln(a);
}
This code prints:
foo barbaz spam
But probably the programmer meant to create an array with 4 strings.
D has the ~ concat operator, so to prevent possible programming bugs it's
better to remove the implicit concat of strings separated by whitespace.
Everywhere the programmer wants to concat strings the explicit concat operator
can be used:
string s = "this is a very long string that doesn't fit in" ~
" a line";
The "Python Zen" has a rule that says:
Explicit is better than implicit.
The compiler can optimize the concat away at compile time.
C code ported to D that doesn't put a ~ just raises a compile time error that's
easy to understand and fix.
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list