Newsgroups: comp.lang.clos
Path: cantaloupe.srv.cs.cmu.edu!das-news2.harvard.edu!oitnews.harvard.edu!purdue!lerc.nasa.gov!magnus.acs.ohio-state.edu!math.ohio-state.edu!howland.reston.ans.net!newsjunkie.ans.net!pipeline!psinntp!psinntp!psinntp!hqda-ai!grant
From: grant@pentagon-ai.army.mil (Pete Grant)
Subject: Re: SLOT-VALUE/WITH-SLOTS vs. standard accessors?
Message-ID: <DEE64r.914@pentagon-ai.army.mil>
Organization: U.S. Army Artificial Intelligence Center, The Pentagon
References: <pch-3008951031120001@198.3.157.39>
Date: Mon, 4 Sep 1995 17:34:02 GMT
Lines: 53

In article <pch-3008951031120001@198.3.157.39> pch@mystech.com (Pete Halverson) writes:
>When I first started using CLOS I tended to use SLOT-VALUE, particularly
>via WITH-SLOTS, fairly heavily, but in the last few years or so I've
>started making much more use of DEFCLASS-defined standard accessors. This
>wasn't really a conscious decision, just that more and more often using an
>accessor felt more "appropriate" than a doing a raw slot access.  In
>trying to explain the difference between the two today, however, I found
>it very difficult to justify the use of WITH-SLOTS or SLOT-VALUE with a
>constant slot name in any but a small set of special circumstances.
>
You're not alone.  I, too have drifted more and more towards accessors.
Incidentally, I usually define only reader accessors, writing most of
my SET methods by hand, often with CHECK-TYPE protection.  I've been
bitten too many times by someone else's (setf (slot-value ...)) with
wrong data type. 

>The other key issue, then, is efficiency, and here I'm somewhat less
>strong in my arguments.   Is SLOT-VALUE always faster than the equivalent
>accessor?  Is it *ever* faster?  When?  I would expect that a CLOS
>implementation *should* (in principle) be able to generate a standard
>reader or writer that's faster than the equivalent SLOT-VALUE call with a
>constant slot name, but I'm vague on how this might be done and I'm
>certainly not knowledgeable on whether it *is* done.  On Genera, at least,
>a few sample timings suggested that the standard reader methods are in
>fact faster than a constant call to SLOT-VALUE, but I daren't make
>conclusions about the rest of the CL arena from this.   Can those who
>*are* familiar with the various CLOS implementations provide any info?
>
I did some testing on this back circa 90 when Genera 8.0 was the 
latest OS.  I was suprised to find that the standard reader/writer
functions were no faster than either programmer-defined methods
nor the SETF methods on slots directly.  I believe I repeated the
tests when 8.1.1 was distributed and found the results to be
the same.

>If efficiency *is* a red herring, could it possible that the apparent
>wide-spread use of WITH-SLOTS is a combination of 
>
>   1) previous exposure to New Flavors or other OO systems in which
>lexical access to slots did not involve a function call; 
>   
>   2) since the SLOT-VALUE is hidden by the name of the symbol macro,
>developers don't immediately make the distinction between a fast local
>variable access and a slow to SLOT-VALUE, such that calling an accessor
>function *seems* like it ought to be slower
>
>   3) there are fewer characters to type.
>
In my case, 3 was the primary reason.

Pete.


