Thread overview | ||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
February 18, 2010 [Issue 3827] New: automatic joining of adjacent strings is bad | ||||
---|---|---|---|---|
| ||||
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@puremagic.com ReportedBy: bearophile_hugs@eml.cc --- Comment #0 from bearophile_hugs@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: ------- |
February 18, 2010 [Issue 3827] automatic joining of adjacent strings is bad | ||||
---|---|---|---|---|
| ||||
Posted in reply to bearophile_hugs@eml.cc | http://d.puremagic.com/issues/show_bug.cgi?id=3827 --- Comment #1 from Alexey Ivanov <aifgi90@gmail.com> 2010-02-18 14:35:32 PST --- Created an attachment (id=571) patch for parse.c Vote++ and patch -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
February 18, 2010 [Issue 3827] automatic joining of adjacent strings is bad | ||||
---|---|---|---|---|
| ||||
Posted in reply to bearophile_hugs@eml.cc | http://d.puremagic.com/issues/show_bug.cgi?id=3827 --- Comment #2 from bearophile_hugs@eml.cc 2010-02-18 14:55:40 PST --- (In reply to comment #1) > Created an attachment (id=571) [details] > patch for parse.c > > Vote++ and patch Thank you. But is DMD doing the joining with ~ at compile time? If not, then you can add that optimization to your patch (if you are able to). -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
February 18, 2010 [Issue 3827] automatic joining of adjacent strings is bad | ||||
---|---|---|---|---|
| ||||
Posted in reply to bearophile_hugs@eml.cc | http://d.puremagic.com/issues/show_bug.cgi?id=3827 --- Comment #3 from bearophile_hugs@eml.cc 2010-02-18 15:03:33 PST --- > Thank you. But is DMD doing the joining with ~ at compile time? If not, then you can add that optimization to your patch (if you are able to). And if you think it's needed, you can add the clear error message I was talking about :-) -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
February 28, 2010 [Issue 3827] automatic joining of adjacent strings is bad | ||||
---|---|---|---|---|
| ||||
Posted in reply to bearophile_hugs@eml.cc | http://d.puremagic.com/issues/show_bug.cgi?id=3827 Alexey Ivanov <aifgi90@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |aifgi90@gmail.com --- Comment #4 from Alexey Ivanov <aifgi90@gmail.com> 2010-02-28 09:36:58 PST --- > Thank you. But is DMD doing the joining with ~ at compile time? If not, then you can add that optimization to your patch (if you are able to). I think DMD is doing joining at compile time (constfold.c, from line 1387) -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
June 20, 2010 [Issue 3827] automatic joining of adjacent strings is bad | ||||
---|---|---|---|---|
| ||||
Posted in reply to bearophile_hugs@eml.cc | http://d.puremagic.com/issues/show_bug.cgi?id=3827 --- Comment #5 from bearophile_hugs@eml.cc 2010-06-20 16:19:15 PDT --- The error message for the missing ~ can be something like this (adapted from the "'l' suffix is deprecated, use 'L' instead" error message generated by the usage of a 10l long literal): adjacent string literals concatenation is deprecated, add ~ between them instead. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
June 20, 2010 [Issue 3827] automatic joining of adjacent strings is bad | ||||
---|---|---|---|---|
| ||||
Posted in reply to bearophile_hugs@eml.cc | http://d.puremagic.com/issues/show_bug.cgi?id=3827 Ellery Newcomer <ellery-newcomer@utulsa.edu> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |ellery-newcomer@utulsa.edu --- Comment #6 from Ellery Newcomer <ellery-newcomer@utulsa.edu> 2010-06-20 16:29:07 PDT --- (In reply to comment #0) > The "Python Zen" has a rule that says: > > Explicit is better than implicit. > the python compiler has a rule that says do the exact same thing as what d is doing. Your serve. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
June 20, 2010 [Issue 3827] automatic joining of adjacent strings is bad | ||||
---|---|---|---|---|
| ||||
Posted in reply to bearophile_hugs@eml.cc | http://d.puremagic.com/issues/show_bug.cgi?id=3827 --- Comment #7 from bearophile_hugs@eml.cc 2010-06-20 16:51:06 PDT --- I know Python, but I hope D will become better than Python on this syntax detail. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
August 21, 2010 [Issue 3827] automatic joining of adjacent strings is bad | ||||
---|---|---|---|---|
| ||||
Posted in reply to bearophile_hugs@eml.cc | http://d.puremagic.com/issues/show_bug.cgi?id=3827 --- Comment #8 from bearophile_hugs@eml.cc 2010-08-21 13:38:59 PDT --- A particularly nice example of why untidy syntax easily leads to bugs (this comes from two different sources of sloppiness of the D2 language): enum string[5] data = ["green", "magenta", "blue" "red", "yellow"]; static assert(data[4] == "yellow"); // asserts void main() {} -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
November 11, 2010 [Issue 3827] automatic joining of adjacent strings is bad | ||||
---|---|---|---|---|
| ||||
Posted in reply to bearophile_hugs@eml.cc | http://d.puremagic.com/issues/show_bug.cgi?id=3827 --- Comment #9 from bearophile_hugs@eml.cc 2010-11-10 18:17:17 PST --- Another bug caused in my code by that anti-feature: unittest { auto tests = [["", "0000"], ["12346", "0000"], ["he", "H000"], ["soundex", "S532"], ["example", "E251"], ["ciondecks", "C532"], ["ekzampul", "E251"], ["resume", "R250"], ["Robert", "R163"], ["Rupert", "R163"], ["Rubin" "R150"], ["Ashcraft", "A226"], ["Ashcroft", "A226"]]; foreach (pair; tests) assert(processit(pair[0]) == pair[1]); } That code compiles with no errors with DMD 2.050, and then causes a Range violation at runtime because one of those arrays isn't a pair. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
Copyright © 1999-2021 by the D Language Foundation