Boost logo

Boost :

From: Jens Maurer (Jens.Maurer_at_[hidden])
Date: 2001-08-05 12:14:54


John Max Skaller wrote:
>
> Jens Maurer wrote:
> >
> > John Max Skaller wrote:
> > > I seek your opinion on get/set vs. get/ref.
 
> Here's the problem. Consider:
 
> struct X { a: int; };
> var x : X;
> x.a = 1;

[Helpful explanation skipped.]

> The compiler has to know '&x.a' and translate it.
> But using set methods, it has to know 'x.a='.

Sure: Since your primary syntax doesn't easily distinguish
between reading and writing, the compiler has to do it
if it wishes to use an interface which does (i.e. get/set).

> An equivalent problem: consider the procedure:
>
> proc doubl (a:&int) { *a = *a + *a; }

[ more explanation skipped]

> The problem is that references
> act to decouple mutators into addressability and subobject
> mutation. Without it, you get OO lunacy: a get and set
> method for every member of a struct.

It appears to me that we've got two levels of (sub-) object
access in C++. One is the struct example you point out above,
where sub-objects of a struct are not obviously connected by
semantic constraints which possibly should be enforced when
writing a new value to one sub-object. This is the C-style
"struct".

Then, there's the OO style where an object knows its
semantic constraints and thus it's useful to distinguish
between reading and writing: Writing needs to perform
additional checks. That doesn't imply that each
sub-object should be written individually; often, writing
several sub-objects at once is easier and "feels" better,
e.g. "contact_info.set_address(struct address)" instead
of "contact_info.set_zip(int)", "contact_info.set_city(string)"
etc.

The language you describe and the examples seem to be more
in the spirit of C structs, so references are potentially
more natural and orthogonal.

> [Despite my comments, I tend to favour get/set. However,
> Felix _is_ intended for C++ programmers who seek a
> very high level language they can learn in a day,
> and which can be used with their existing C++ code
> with very little effort]

Does that mean that you possibly need to support both options?

Jens Maurer


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk