string concatenation

div0 div0 at users.sourceforge.net
Thu Nov 19 12:12:08 PST 2009


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Justin Johansson wrote:
> 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.
> 
Also you'll be calling some behind the scenes runtime library function
to do it anyway, in order to encode the dchars to multiple wchars.

All seems a bit pointless really.

- --
My enormous talent is exceeded only by my outrageous laziness.
http://www.ssTk.co.uk
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iD8DBQFLBaaYT9LetA9XoXwRAgxQAKCwdo12XokImcAX+A97VzmIywNuIgCdH1JG
BTP5L+COxR704lknJMTkjRI=
=Dljj
-----END PGP SIGNATURE-----



More information about the Digitalmars-d mailing list