Why Strings as Classes?

Steven Schveighoffer schveiguy at yahoo.com
Wed Aug 27 12:53:22 PDT 2008


"Dee Girl" wrote
> I think depends on good design. For example I think ++ or -- for iterator. 
> If it is O(n) it is bad design. Bad design make people say like you "This 
> is what you get with operator overloading".

Slightly off topic, when I was developing dcollections, I was a bit annoyed 
that there was no opInc or opDec, instead you have to use opAddAssign and 
opSubAssign.  What this means is that for a list iterator, if you want to 
allow the syntax:

iterator it = list.find(x);
(++it).value = 5;

or such, you have to define the operator opAddAssign.  This makes it 
possible to do:

it += 10;

Which I don't like for the same reason we are arguing about this, it 
suggests this is a simple operation, when in fact, it is O(n).  But there's 
no way around it, as you can't define ++it without defining +=.  Of course, 
I could throw an exception, but I decided against that.  Instead, I just 
warn the user in the docs to only ever use the ++x version.

Annoying...

-Steve 





More information about the Digitalmars-d mailing list