Why Strings as Classes?

Benji Smith dlanguage at benjismith.net
Tue Aug 26 13:09:35 PDT 2008


Denis Koroskin wrote:
>> I agree. You can't rely on function invokation, i.e. the following 
>> might be slow as death:
>>
>> auto n = collection.at(i);
>> auto len = collection.length();
>>
>> but index operations and properties getters should be real-time and 
>> have O(1) complexity by design.
>>
>> auto n = collection[i];
>> auto len = collection.length;
> 
> The same goes to assignment, casts, comparisons, shifts, i.e. everything 
> that doesn't have a function invokation syntax.

This is the main reason I dislike D's optional parentheses for function 
invocations:

   something.dup; // looks cheap
   something.dup(); // looks expensive

Since any zero-arg function can have its parens omitted, it's harder to 
read code and see where the expensive operations are.

--benji



More information about the Digitalmars-d mailing list