[Top][All Lists]

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

Re: Opaque objects and Emacs documentation

From: João Távora
Subject: Re: Opaque objects and Emacs documentation
Date: Wed, 22 Jul 2020 12:43:38 +0100

On Sun, Jul 19, 2020, 23:02 Dmitry Gutov <dgutov@yandex.ru> wrote:
On 18.07.2020 04:54, Richard Stallman wrote:
> We define an accessor defsubst for each of the data it contains.  We
> document its meaning.  We define a constructor function, and document
> the meaning of each argument.  We manipulate them always through those
> functions.  Voilà!

Here's a question that will perhaps help us solve this dispute.

Consider the docstring of said constructor function. What should it say
its return value is?

IMHO, a most reasonable way to answer this question, for any function, but particularly for generic ones: 

"Return an object which one can pass to/responds to 'foo' and 'bar', which see".

It's pretty helpful already. If you can add things to be more helpful, like mentioning a type (which may be just a deftype) you should, but oftentimes duck typing and generic functions means you're better off talking in terms of operations.

In the docstring of methods of the generic functions you can be more specific as to how the object returned responds to foo and bar.

This is fundamentally different from the  Java OO paradigm. In Common Lisp, function is king.

But generic functions are not at all the only way to successfully design abstractions in CL. IME of about 15 years, they're good because they mix well with defclass via method combinations (of which Emacs's version of generics only has the one). Method combinations "understand" the object hierarchy. When you're not using them with defclass, they become so-so, on par or sometimes even slightly behind many other techniques. 

As a very rough rule of thumb, if you're not using 'call-next-method' anywhere, or don't see a good reason why, you've probably overengineered it.

PS: i'm just replying to this bit of context, no idea how it fits in the general discussion and whose position this helps, if anyone's...


reply via email to

[Prev in Thread] Current Thread [Next in Thread]