Why Strings as Classes?

lurker lurker at lurk.com
Wed Aug 27 22:45:48 PDT 2008


Nick Sabalausky Wrote:

> "Dee Girl" <deegirl at noreply.com> wrote in message 
> news:g94k7i$2ahk$1 at digitalmars.com...
> > Derek Parnell Wrote:
> >
> >> On Wed, 27 Aug 2008 17:08:47 -0400, Nick Sabalausky wrote:
> >>
> >> > The way I see it, encapsulation is all about the black box idea. And 
> >> > the
> >> > only things you can see from outside the black box are the inputs and
> >> > outputs.
> >>
> >> Well said.
> >
> > I am sorry I will say my opinion. This sounds good but is simplistic. 
> > Black box is good in principle. But it assume you found right interface 
> > for the black box. If you define bad interface you have a bad black box. 
> > Also please remember that iterator is black box also. But it defines right 
> > interface.
> >
> >> > Indexing: Return the element at position N.
> >> > Find: Return the position of the element that is equal (value-equal or
> >> > identity-equal, depending on the find) to X .
> >>
> >> Exactly.
> >>
> >> > So if there's a function that returns the element at position N and you 
> >> > call
> >> > it "find" just because of the *internal implementation* of the function 
> >> > is
> >> > an incrementing loop, I consider that to be both a violation of
> >> > encapsulation (because the name has been chosen based on the inner 
> >> > workings
> >> > of the function, not it's input-output relationship) and a violation of 
> >> > the
> >> > definitions.
> >>
> >> Not to mention just plain confusing.
> >
> > 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
> >
> 
> Making [] do "find" is never good. The [n] should always mean "return the 
> element at position n". That is never "find", it's always "indexing" 
> (Although some people here have disagreed and claimed that "return the 
> element at position n" on a linked list is "find", which might be why you're 
> confused).

(I hate myself for letting myself getting into this......)

It's you who is confused, and badly. More over I think Dee said she's confused sort of ironically. Her posts are nowhere near confusion. I can only say she kicks some serious butt. She merly reveals your confusion. Whenever she says something we should be listening. 

Come to your senses. Open any algorithms book. Finding the nth element in a list is linear search. It does not matter whether you are looking for a value or an index. Search is search is search. Claiming a linear search it's not a linear search is just empty retoric and semantic masturbation.

At the beginning of this huge thread I was straight in the I-dont-care-about-theory-crap-opIndex-is-convenient camp. But the arguments put forth especially by Dee and (I hate to say it), Dan (Dan you ARE a pompous prick) got me seriously thinking. Dee had me at the contract metaphor.



More information about the Digitalmars-d mailing list