Why Strings as Classes?

Christopher Wright dhasenan at gmail.com
Wed Aug 27 16:09:53 PDT 2008


Dee Girl wrote:
> I am confused to. Why is making [] do find good and making find do [] wrong? How do you make decision? To me it looks the opposite way. Because find is less demanding contract than []. In design a stronger contract can replace a weaker contract. Not the inverse. Thank you, Dee Girl

Choosing the data structure used is never the job of the code you're 
giving the data to. It's the job of whatever creates the data structure. 
By giving two functions where the only difference is performance 
guarantees, you're allowing the called code to determine what data 
structures it accepts, not based on the operations the structure 
supports, but based on the performance of those data structures.

D's standard arrays are a bad example of this: since they're built in, 
everyone uses them, so it's difficult to replace them with a linked list 
or something else. The effect is more pronounced with associative 
arrays, since there isn't as much choice in lists as in dictionaries. 
But they're so damn useful, and the syntax is hard to match.



More information about the Digitalmars-d mailing list