Why the hell doesn't foreach decode strings
Walter Bright
newshound2 at digitalmars.com
Thu Oct 20 20:37:40 PDT 2011
On 10/20/2011 7:37 PM, Jonathan M Davis wrote:
> True, but if the default were dchar, then the common case would be have fewer
> bugs
Is that really the common case? It's certainly the *slow* case. Common string
operations like searching, copying, etc., do not require decoding.
> (still allowing you to explicitly use char or wchar when you want to). At
> minimum, I think that it would be a good idea to implement
> http://d.puremagic.com/issues/show_bug.cgi?id=6652 and make it a warning not
> to explicitly give the type with foreach for arrays of char or wchar. It would
> catch bugs without changing the behavior of any existing code, and it still
> allows you to iterate over either code units or code points.
I like the type deduction feature of foreach, and don't think it should be
removed for strings. Currently, it's consistent - T[] gets an element type of T.
I want to reiterate that there's no way to program strings in D without being
cognizant of them being a multibyte representation. D is both a high level and a
low level language, and you can pick which to use, but you still gotta pick.
More information about the Digitalmars-d
mailing list