string is rarely useful as a function argument

Gor Gyolchanyan gor.f.gyolchanyan at gmail.com
Thu Dec 29 00:12:40 PST 2011


This a a great idea! In this case the default string will be a
random-access range, not a bidirectional range. Also, processing
dstring is faster, then string, because no encoding needs to be done.
Processing power is more expensive, then memory. utf-8 is valuable
only to pass it as an ASCII string (which is not too common) and to
store large chunks of it. Both these cases are much less common then
all the rest of string processing.

+1

On Thu, Dec 29, 2011 at 12:04 PM, Vladimir Panteleev
<vladimir at thecybershadow.net> wrote:
> On Wednesday, 28 December 2011 at 19:00:53 UTC, Andrei Alexandrescu wrote:
>>
>> On 12/28/11 12:46 PM, Walter Bright wrote:
>>>
>>> On 12/28/2011 10:35 AM, Peter Alexander wrote:
>>>>
>>>> On 28/12/11 6:15 PM, Walter Bright wrote:
>>>>>
>>>>> If such a change is made, then people will use const string when they
>>>>> mean immutable, and the values underneath are not guaranteed to be
>>>>> consistent.
>>>>
>>>>
>>>> Then people should learn what const and immutable mean!
>>>>
>>>> I don't think it's fair to dismiss my suggestion on the grounds that
>>>> people
>>>> don't understand the language.
>>>
>>>
>>> People do what is convenient, and as endless experience shows, doing the
>>> right thing should be easier than doing the wrong thing. If you present
>>> people with a choice:
>>>
>>> #1: string s;
>>> #2: immutable(char)[] s;
>>>
>>> sure as the sun rises, they will type the former, and it will be subtly
>>> incorrect if string is const(char)[].
>>>
>>> Telling people they should know better and pick #2 instead is a strategy
>>> that never works very well - not for programming, nor any other endeavor.
>>
>>
>> Oh, one more thing - one good thing that could come out of this thread is
>> abolition (through however slow a deprecation path) of s.length and s[i] for
>> narrow strings. Requiring s.rep.length instead of s.length and s.rep[i]
>> instead of s[i] would improve the quality of narrow strings tremendously.
>> Also, s.rep[i] should return ubyte/ushort, not char/wchar. Then, people
>> would access the decoding routines on the needed occasions, or would
>> consciously use the representation.
>
>
> I think it would be simpler to just make dstring the default string type.
>
> dstring is simple and safe. People who want better memory usage can use
> UTF-8 at their own discretion.



-- 
Bye,
Gor Gyolchanyan.


More information about the Digitalmars-d mailing list