caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: John Max Skaller <skaller@maxtal.com.au>
To: boost@yahoogroups.com, caml-list@inria.fr
Subject: [Caml-list] RFC: get/set vs get/ref
Date: Thu, 12 Jul 2001 11:49:01 +1000	[thread overview]
Message-ID: <3B4D020D.4039A62F@maxtal.com.au> (raw)
In-Reply-To: <00a701c10a15$9b1db190$6701a8c0@abeast1.com>

[posted to caml-list@inria.fr and boost@yahoogroups.com]

I seek your opinion on  get/set vs. get/ref.

Suppose we desire to abstract an immutable data type.
We can do that by providing 'get' methods to access
the data. The canonical examples are

	a) tuples: represented by projection functions
	b) lists: represented by 'head' and 'tail' functions

When the data type is mutable, there are two choices.
The simplest choice is to provide set methods.
For example, for a mutable string, with C++ notation:

	char string::get_char (int pos) const
	void string::set_char (int pos, char ch)

For Algol like languages, we could also provide references:

	char string::get_char (int pos)const
	char &string::ref_char (int pos)

The difference is exemplified by the following techniques
for incrementing a character:

	s.set ((s.get(pos) + 1),pos)  // get/set method
	s.ref(pos).++                 // ref method

Clearly, ref methods are more powerful and more efficient,
but on the other hand they expose the underlying implementation
and prevent hooking changes to the mutable state.

What's the best technique?

-- 
John (Max) Skaller, mailto:skaller@maxtal.com.au 
10/1 Toxteth Rd Glebe NSW 2037 Australia voice: 61-2-9660-0850
New generation programming language Felix  http://felix.sourceforge.net
Literate Programming tool Interscript     
http://Interscript.sourceforge.net
-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr


       reply	other threads:[~2001-07-14  1:14 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <Pine.LNX.4.33.0107110922490.1683-100000@localhost.localdomain>
     [not found] ` <0107111558020P.12210@baxter>
     [not found]   ` <00a701c10a15$9b1db190$6701a8c0@abeast1.com>
2001-07-12  1:49     ` John Max Skaller [this message]
2001-07-14  3:10       ` Bruce Hoult
2001-07-14  8:52       ` William Chesters

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3B4D020D.4039A62F@maxtal.com.au \
    --to=skaller@maxtal.com.au \
    --cc=boost@yahoogroups.com \
    --cc=caml-list@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).