[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Why would anyone want opacity?

   Date: Wed, 8 May 1996 13:55:45 -0400
   From: Mitchell Wand <wand@ccs.neu.edu>
   My students try to debug their code.  They observe that the tables are
   implemented as 2-element lists.  Pretty soon they stop writing
   "get-x-value", and start writing "car" instead.  Their code starts to
   work.  They are happy.  They write much, much code...

   Then I decide to change the implementation of 2-element tables ...

   Their code stops working.  Not only does their code stop working, ...

All true.

   The point of this was that it is insufficient
   to merely decree, as Jeff suggests that

   > students and other inexperienced programmers can stay out of trouble
   > just by not using record-{length,ref,set!}.

   Among other things, the student programmers (the clients of the ADT)
   probably need these operations for their own uses, so they can't simply
   be made illegal-- in our case, we probably don't want to make CAR
   illegal in student code.

Wait.  Wait, wait, wait.  Hold on.  Stop.

`car' is not `record-ref'.  `car' is something you call all the time
because there are many things in the language that explicitly manipulate
lists (`assq', `map', `eval', ...).  `record-ref' (as I understand Jeff's
proposal) is something that nobody ever calls -unless- they are breaking
abstraction.  Nobody.  Not the definer of the record type.  Not the clients
of the record type.  You could reasonably change the name to be


and your students would have to be pretty dense not to realize they're
calling something that will get them in trouble.  (Or for students, just
keep those procedure out of their environment -- they don't need them.)

The only people who -ever- call this procedure are people like Bill Rozas
who are writing tools like debuggers.

The analogous abstraction-breaking procedure in the `make-record-type'
proposal (the one that's now eight years old) is the procedure
`record-type-descriptor'.  I have a personal implementation of this package
that I use all the time.  I just searched through all of my own code and I
found that `record-type-descriptor' is called in -one- place outside of the
file that implements records themselves.  That one place is a little tool I
wrote that lets me inspect arbitrary Scheme data structures through a
Web-browser.  I offer this example both to demonstrate how rare it is to
call such a procedure and to illustrate how useful it can be when you do
call it.