Why Strings as Classes?

Nick Sabalausky a at a.a
Wed Aug 27 21:48:44 PDT 2008


"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).





More information about the Digitalmars-d mailing list