Re: Holub on getters/setters again

From: Ron Jeffries (ronjeffries_at_REMOVEacm.org)
Date: 01/25/04


Date: Sun, 25 Jan 2004 07:46:24 -0500

On Sun, 25 Jan 2004 06:14:06 GMT, "Daniel T." <postmaster@eathlink.net> wrote:

>> Nonetheless, in this context the ArrayList seems almost equally tacky to me
>> whether copied or not. If you agree, what rule of thumb or other digit would
>> you
>> use to call attention to this?
>
>I've been wondering the same myself. I've started to post a thought
>several times, but stopped because the thought isn't complete yet... But
>here it goes anyway.
>
>Once the Contents method is changed into a factory method as I have
>suggested. It can almost be said that it isn't a getter anymore even by
>my definition of the word. What it is returning isn't the state of the
>Set, but another object that happens to have the same state as the set.
>There may be a problem inherent with that.

Yes, I think so. It isn't "just happens". The intention is that it does have the
same state. There is, as far as I can see, no reason to have the ArrayList at
all. It should, in principle, offer no functionality that the Set could not.
>
>Part of the problem, it seems to me, is that the Set class was written
>before the client that uses it was written. If you had written the
>client code first, you would have naturally called foreach on the Set
>itself. When the servers implementation is running the show, things get
>messed up. In this case, the server's implementation decided the servers
>interface, which forced the client code to be written a certain way.
>This is backwards from how it should be. It should be the client
>implementation determining the server interface...

This is an interesting fantasy but it is counter to fact. I wrote the Set when I
needed it. And I knew I wanted to call foreach on it from the very beginning,
both because of the current client and because I know what collections are
supposed to do.

The reason that I didn't implement foreach was that it is slightly tricky, I've
only done it once in C#, and I was on a mission to get something done. So the
hack of returning the ArrayList let me return to the real purpose.

It's true that implementing Set first in a clueless fashion might have led to
the same result. But when you consider that they are all my code, in my program,
and if you grant me the possibility of having a clue about what's good and
what's bad, it's necessary to look for another reason. In this case the reason
is simple, and fairly common in real life: I can get done faster if I do this in
a less than optimal way.

If I add the Set to my general library of objects, this reasoning will remain
oddly true ... every time I need to loop over a set, it will be easier to just
call Contents and loop over it. But every time I do this, there will be an extra
method call in the code. Over time, it will add up to worse and worse code all
over the universe, until finally we are all bogged down in calls to Contents.

I hope that I have the energy to do it right before that happens. ;->

-- 
Ronald E Jeffries
http://www.XProgramming.com
http://www.objectmentor.com
I'm giving the best advice I have. You get to decide whether it's true for you.


Relevant Pages

  • Re: Holub on getters/setters again
    ... There is, as far as I can see, no reason to have the ArrayList at ... >>before the client that uses it was written. ... And I knew I wanted to call foreach on it from the very beginning, ... whether the element already exists in that container. ...
    (comp.object)
  • Re: 2000 server is losing data files
    ... We have a client that has both a 2000 & a 2003 server that are not on ... For some totally unknown reason that we can not understand, ... chunk of this Admin folder should vanish. ... We manage a large number of servers and have never come across ...
    (microsoft.public.security)
  • Re: [fw-wiz] Defense in Depth to the Desktop
    ... > network hardware mechanisms. ... The Strong Internal Network Defense ... The client subnet and the server ... Servers are allowed to reply to clients, ...
    (Firewall-Wizards)
  • [fw-wiz] Defense in Depth to the Desktop
    ... network hardware mechanisms. ... controls is highlighted when the internal network and systems suffer ... The client subnet and the server ... Servers are allowed to reply to clients, ...
    (Firewall-Wizards)
  • Re: [fw-wiz] Defense in Depth to the Desktop
    ... Sounds a lot like Domain Based Security (not Windows 'domains', ... > network hardware mechanisms. ... The client subnet and the ... Servers are allowed to reply to clients, ...
    (Firewall-Wizards)