You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@subversion.apache.org by Ben Collins-Sussman <su...@collab.net> on 2001/11/30 17:24:34 UTC

Re: PUBLIC POLL: final static VARIABLE

+1 direct variable access.

Even though I'm only 28 years old, I feel like an ancient curmudgeon.
I learned C++ ten years ago, and in those days we thought of instance
objects as "structures with methods".  But a class instance is still a
*structure*.  Why can't you look at the structure's fields?  Why do we
need to create the extra distance through accessor methods?  I mean,
if you don't want your fields mucked with, that's why we have
'private' variables in a class.  Accessors are for returning
information about private variables, or so I thought.

But maybe Ruby and Java have done away with all that.  I'm not up on
the latest philosophies anymore.  It seems that the extra formality
would just get in the way.

All I know is:  in my day, we used class variables directly... and we
LIKED it!  ;-)



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org

Re: PUBLIC POLL: final static VARIABLE

Posted by Daniel Rall <dl...@finemaltcoding.com>.
Ben Collins-Sussman <su...@collab.net> writes:

> Russ Allbery <rr...@stanford.edu> writes:
>
>> Basically, accessor functions let you isolate clients of your object from
>> data type changes and algorithm changes that cause things that used to be
>> static information to become computed information.
>
> Hm, OK.  I'm sold.  This makes a lot of sense. 

And it's a lot more familiar for people who do work with Java.
Making them happier about working with SVN's Java bindings...

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org

Re: PUBLIC POLL: final static VARIABLE

Posted by Ben Collins-Sussman <su...@collab.net>.
Russ Allbery <rr...@stanford.edu> writes:

> Basically, accessor functions let you isolate clients of your object from
> data type changes and algorithm changes that cause things that used to be
> static information to become computed information.

Hm, OK.  I'm sold.  This makes a lot of sense. 


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org

Re: PUBLIC POLL: final static VARIABLE

Posted by Russ Allbery <rr...@stanford.edu>.
Ben Collins-Sussman <su...@collab.net> writes:

> Even though I'm only 28 years old, I feel like an ancient curmudgeon.
> I learned C++ ten years ago, and in those days we thought of instance
> objects as "structures with methods".  But a class instance is still a
> *structure*.  Why can't you look at the structure's fields?

The primary reason not to do things this way is because it constrains your
future implementation.

To use a constructed example, suppose that you have an object that
represents a file.  Among the information that it stores is an offset into
the file, stored as the appropriate integer type.

All good.  Clients can access it directly.  No need for those annoying
accessor functions.

But wait... you then port the object to an operating system that doesn't
use flat offsets.  It instead represents file positions by a struct that
contains a "page" number and an offset into that page.  Aaaa!

After a lot of work, you manage to hide that complexity from your clients
by assembling and disassembling flat offsets from the native offset
struct... except that all your clients are directly reading your object
data and expect to see an integer there.  So you now have to add another
field to your object called real_offset containing a struct with the page
and offset, the field that all the clients are using becomes a computed
field, and now you have to keep both of them in sync whenever they change
just in case something directly reads the pure integer offset.  Ick.

Now suppose you'd used an accessor function.  All you have to do is modify
the accessor function to compute the integer value rather than just
returning the field of the object, and all of the clients behave the same.
You can then safely change the object field to store the native offset in
whatever way is most convenient for portable coding.  No need to store the
same data twice, no need to do extra work (you only have to do the
computation when something actually asks for the flat offset).

Basically, accessor functions let you isolate clients of your object from
data type changes and algorithm changes that cause things that used to be
static information to become computed information.

-- 
Russ Allbery (rra@stanford.edu)             <http://www.eyrie.org/~eagle/>

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org

Re: PUBLIC POLL: final static VARIABLE

Posted by Florin Iucha <fl...@iucha.net>.
On Fri, Nov 30, 2001 at 11:24:34AM -0600, Ben Collins-Sussman wrote:
> 
> +1 direct variable access.
> 
> Even though I'm only 28 years old, I feel like an ancient curmudgeon.
> I learned C++ ten years ago, and in those days we thought of instance
> objects as "structures with methods".

You thought it wrong. Take that book and quietly burn it before the OO
police knocks on your door.

"structures with methods" were a convenience ment to lure away people from
C into C++...

>                                        But a class instance is still a
> *structure*. 

No, it's not a structure. It's an opaque object that exhibits certain
behaviors.

>              Why can't you look at the structure's fields?  Why do we
> need to create the extra distance through accessor methods? I mean,
> if you don't want your fields mucked with, that's why we have
> 'private' variables in a class.

He was specifically refering to having "private" attributes that he
wanted to make public...

>                                 Accessors are for returning
> information about private variables, or so I thought.

No! Accessors return the values of "properties". If it happens that the
property is implemented _now_ as an atribute, that's an implementation artifact
that might not be valid next year, when you need to look that up somewhere...

> But maybe Ruby and Java have done away with all that.  I'm not up on
> the latest philosophies anymore.  It seems that the extra formality
> would just get in the way.
> 
> All I know is:  in my day, we used class variables directly... and we
> LIKED it!  ;-)

Did you mother know? :)

Public attributes would not pass through a code review in any organisation
I have been so far...

In our latest project we have adopted the Sun patterns for the XML parser
package: declare the interfaces for everything then write implementations for
them and provide access to the implementations via factory objects, so we can
replace implementations at any time. Just a thought...

florin

-- 

"If it's not broken, let's fix it till it is."

41A9 2BDE 8E11 F1C5 87A6  03EE 34B3 E075 3B90 DFE4