[plt-scheme] Naming style

From: Eli Barzilay (eli at barzilay.org)
Date: Sat Feb 14 17:04:46 EST 2009

On Feb 13, Will Duquette wrote:
> Warning: I am a clueless newbie when it comes to PLT-Scheme (though I
> have some slight background with Lisp-like languages).
> I've just started glancing at "An Introduction to Scheme with
> Pictures", which uses something called "#lang slideshow".  Almost
> immediately I see the function "hc-append".  When I go look at the
> docs, as suggested, I see that it's one of a family of functions, all
> of which follow this naming convention:
>     <options>-<operation>
> Thus, this command appends pictures together horizontally ("h"),
> centering them vertically. ("c").
> This strikes me as a very add way to name functions; I'd have
> thought that having one function, "append", with arguments
> indicating the alignment, would make more sense.  On the other hand,
> someone implemented it this way on purpose, and given that it's used
> in a document for newbies like me I presume it's good style.  Would
> someone care to explain to me *why* it's good style?

There are two arguments for this that I can think of (disclaimer: I'm
not the one who wrote that interface...):

1. It was designed before PLT had an organized way for using keyword
   arguments, which are one of the obvious ways to make a more
   convenient interface.

2. Having separate bindings for `hc-append' and `vc-append' (for
   example) mean that you'll get feedback of whether you wrote the
   right thing immediately: if there is no `vc-append' (or if you made
   some typo) then the code wouldn't even compile, and you'll know
   that you need to fix it.

   OTOH, you could have a mode argument, and have `append' check it
   and either use the mode or throw an error -- that means that you
   only get an error when you try to run the code.  BTW, there is also
   an option of:

     (define (append mode blah ...)
       (let ([horiz (eq? mode 'horizontal)])

   which means that a user typo like

     (append 'horiz)

   will silently use vertical mode, which can be very confusing.

          ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:
                  http://www.barzilay.org/                 Maze is Life!

Posted on the users mailing list.