Subject: [clisp-list] critique of default-foreign-language & API design questions

From: "Hoehle, Joerg-Cyril" <[email-masked]>
Date: Wed Apr 17 02:32:21 2002

Hi,

Sam Steingold wrote:
> having separate def-c-call-out, def-win32-call-out &c is "the scheme
> way" (TM)  :-)

It's not. It supports people's (including programmers)
natural lazyness and concisely expresses exactly what's needed,
which is valuable.
Remember when I said "attempt to make programmer state the obvious".

I'll expand on what I consider a design question:

I'm considering changing dynload.d's
# (FFI:RESOLVE-FOREIGN-NAME name lib &optional os-option)
into
(LOCATE-FOREIGN-VARIABLE name lib) and
(LOCATE-FOREIGN-FUNCTION name lib)

One might consider this to be superfluous. OS-option (currently
unused on UNIX and MS-Windows) would be used to mean "as a variable", so
(LOCATE-FOREIGN-FUNCTION name lib) = (resolve-foreign-name name lib NIL)
(LOCATE-FOREIGN-VARIABLE name lib) = (resolve-foreign-name name lib T)

What's the rationale behind such a change?

FUNCTION vs. VARIABLE only makes a difference on platforms
with HAVE_SHL_LOAD (HP/UX). It doesn't make a difference on
other platforms (dlopen(), MS-Windows etc.). There sysdll's
dll_function() and dll_variable() map to the same call.

My goal is to have programmers on the other platforms easily
(and reliably) write code that will work there too
-- without crashes or changes.

Programmers on the other platforms will tend to forget about
the extra parameter to RESOLVE-FOREIGN-NAME, partly because they
may not recognize the importance of a difference not visible to them,
partly because their code will work in any case.
So their testing doesn't show bugs.

With LOCATE-FOREIGN-FUNCTION/VARIABLE however, the situation is
completely different.
By sole virtue of the name, programmers on any platform will notice
that there's something wrong should they happen to write (or read):

(ensure-foreign-FUNCTION
  (or (locate-foreign-VARIABLE "compress" "zlib")
      (error "not found"))
  '(c-function (:arguments #) #))

That's how I could "show by example" that API design *has* an
influence on the robustness and liability of software to crash
after the next patch or next port.

BTW, I plan to give a course sometime this year, somewhere in
Germany, on API design. This could be one of the topics covered.

Regards,
	Jorg Hohle.
Working in IT-Security, Software reliability and dependability
area inside the German Telekom group.
There's a lot of power to names (find appropriate quote :).

---

From: Sam Steingold <[email-masked]>
Date: Wed Apr 17 10:03:02 2002

> * In message <[email-masked]>
> * On the subject of "[clisp-list] critique of default-foreign-language & API design questions"
> * Sent on Wed, 17 Apr 2002 11:30:59 +0200
> * Honorable "Hoehle, Joerg-Cyril" <[email-masked]> writes:
>

Or no!! Please don't!!
there will be a lot of code duplication between your
LOCATE-FOREIGN-FUNCTION and LOCATE-FOREIGN-VARIABLE.

Please make the optional os-option a _required_ argument instead:
        (FFI:RESOLVE-FOREIGN-NAME name lib type)
where type is is either :FUNCTION or :VARIABLE

> after the next patch or next port.

this is handled by making the last arg required too.

-- 
Sam Steingold (http://www.podval.org/~sds) running RedHat7.2 GNU/Linux
Read, think and remember! <http://www.iris.org.il> <http://www.memri.org/>
<http://www.palestine-central.com/> <http://www.mideasttruth.com/>
History doesn't repeat itself, but historians do repeat each other.

---

From: Christophe Rhodes <[email-masked]>
Date: Wed Apr 17 10:41:18 2002

> LOCATE-FOREIGN-FUNCTION and LOCATE-FOREIGN-VARIABLE.

So why not

(defun shared-logic-for-foreign-names (name lib &rest otherargs)
  ...)

(defun locate-foreign-function (...)
  (do-function-specific-stuff (shared-logic-for-foreign-names ...)))

(defun locate-foreign-variable (...)
  (do-variable-specific-stuff (shared-logic-for-foreign-names ...)))

?

Logic duplication doesn't need to imply code-duplication.

Cheers,

Christophe
-- 
Jesus College, Cambridge, CB5 8BL                           +44 1223 510 299
http://www-jcsu.jesus.cam.ac.uk/~csr21/                  (defun pling-dollar 
(str schar arg) (first (last +))) (make-dispatch-macro-character #\! t)
(set-dispatch-macro-character #\! #\$ #'pling-dollar)