string concatenation
Justin Johansson
no at spam.com
Wed Nov 18 21:28:21 PST 2009
Andrei Alexandrescu wrote:
> TDPL boasts the code:
>
> void main()
> {
> string a = "Hall\u00E5";
> wstring b = ", ";
> dstring c = "V\u00E4rld";
> auto d = b ~ c; // d has type wstring, same as b
> a ~= d ~ '!'; // concatenate string with character
> writeln(a);
> }
>
> We are having second thoughts about allowing b ~ c. It may be just a bit
> too clever. Also, figuring out the result type is not a slam dunk. The
> pro arguments are that strings are already supported by the compiler in
> iteration, literals, and concatenation of a char[] with a dchar.
>
> What say you?
>
>
> Andrei
Good; have third thoughts as well; the TDPL code is nothing to boast about.
Basically no thanks.
con argument
1. Explicit conversion between string types is clearer to read in source
code than auto-magic conversion.
2. Value types should be supported by constructor functions (and these
can allow type conversion); hiding construction behind binary operators
is evil.
3. People will end up writing concatenation with empty string to do
their type conversion. This is the result of such evil.
4. Programs sprinkled with mixtures of strings, wstrings and dstrings
are uncommon so it's trying to be a bit too clever to support the
infrequent use cases.
5. It's less work for you and Walter to not allow such behind the scenes
conversion.
Justin Johansson
More information about the Digitalmars-d
mailing list