From: Drew Adams <drew.adams@oracle.com>
To: John Wiegley <johnw@gnu.org>
Cc: Philipp Stephani <phst@google.com>,
Philipp Stephani <p.stephani2@gmail.com>,
emacs-devel@gnu.org
Subject: RE: [PATCH] Add new function to test whether a key is present in a hash table.
Date: Mon, 19 Feb 2018 09:26:37 -0800 (PST) [thread overview]
Message-ID: <6af0cc2c-b5ba-4736-8772-1c10f0e95dec@default> (raw)
In-Reply-To: <m237215svl.fsf@newartisans.com>
> DA> 2. The function name should have `key' in it, I think. Suggestion:
> DA> `hash-table-contains-key-p' or even just `hash-table-key-p'.
>
> It seems a bit strange that the name isn't something like "hashash",
> since knowing "puthash" and "gethash" would never help you guess
> hash-table-contains-key-p.
Right. And knowing `hash-table-contains-key-p' wouldn't
help you guess `puthash' or `get-hash'.
But that's the fault of `puthash' and `gethash'. ;-)
It's `puthash' and `gethash' that are not so conventional
for Emacs. They are borrowed from Common Lisp. Likewise,
`maphash', `remhash', and `clrhash'. Those names predate
Common Lisp even.
`puthash', `gethash', `remhash', etc. could be made
aliases of, say, `hash-table-put', `hash-table-get',
`hash-table-remove', etc. (I'm not saying they should.)
`puthash' seems to be the only Emacs `put*' function
whose name doesn't start with `put-' (apart from `put'
itself). Same thing for `gethash' (except that there
are also `getenv' and `getf'). The Emacs convention is
to use prefix `put-' or `get-'.
Another (more common?) convention in Emacs is to put the
object type first: `string-match', `bool-vector-union',
`mode-line-next-buffer', `menu-bar-open', `marker-buffer',
`buffer-size', `window-child', `frame-edges', etc.,
especially for functions that extract parts of an object.
Yet another convention is to put the verb first,
especially for "utility" verbs: `map-*', `make-*',
`put-*', `get-*', `copy-*', `delete-*', etc.
Finally, a library prefix is often used: `ad-get-*',
`ange-ftp-get-*', `bookmark-get-*', `comint-get-*',
`dired-get-*', `ediff-get-*', `gnus-get-*' ...
These are the functions I see with "hash" in their names:
0. Those that (I guess) have nothing to do with hash tables:
ange-ftp-guess-hash-mark-size
ange-ftp-process-handle-hash
buffer-hash
gnutls-hash-digest
hashcash-insert-payment
hashcash-insert-payment-async
hashcash-verify-payment
rfc2104-hash
sxhash
sxhash-eq
sxhash-eql
sxhash-equal
I mention these to point out that names like `puthash'
don't really, on their own, make clear that they have
to do with a hash table.
1. Those that are about hash-table hashing but (I guess)
don't have a hash table as the main object:
gnus-create-hash-size
gnutls-hash-mac
secure-hash
secure-hash-algorithms
2. Those (non-CL) that have a hash table as the main object:
ange-ftp-hash-entry-exists-p
ange-ftp-hash-table-keys
clrhash
copy-hash-table
define-hash-table-test
define-translation-hash-table
gethash
gnus-make-hashtable
hash-table-count
hash-table-p
hash-table-rehash-size
hash-table-rehash-threshold
hash-table-size
hash-table-test
hash-table-weakness
make-hash-table
maphash
puthash
remhash
ucs-normalize-make-hash-table-from-alist
3. Common-Lisp emulation functions for hash tables:
cl-clrhash
cl-gethash
cl-hash-table-count
cl-hash-table-p
cl-make-hash-table
cl-maphash
cl-not-hash-table
cl-puthash
cl-remhash
Note that except for those names inherited from older
Lisps, Common Lisp spells out `hash-table' in the
function names.
The most common convention, so far, for Emacs hash-table
functions is to start the function name with `hash-table'.
That accords with the convention of putting the object
name first.
next prev parent reply other threads:[~2018-02-19 17:26 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <<20180215203406.64372-1-phst@google.com>
2018-02-15 22:08 ` [PATCH] Add new function to test whether a key is present in a hash table Drew Adams
2018-02-15 23:35 ` Eric Abrahamsen
2018-02-16 6:51 ` John Wiegley
2018-02-18 14:29 ` Richard Copley
2018-02-19 6:02 ` John Wiegley
2018-02-19 17:26 ` Drew Adams [this message]
2018-02-15 20:34 Philipp Stephani
2018-02-15 22:03 ` Clément Pit-Claudel
2019-04-19 17:33 ` Philipp Stephani
2018-02-15 22:59 ` Stefan Monnier
2018-02-16 1:03 ` Drew Adams
2018-02-16 1:59 ` Stefan Monnier
2018-02-16 2:50 ` Drew Adams
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=6af0cc2c-b5ba-4736-8772-1c10f0e95dec@default \
--to=drew.adams@oracle.com \
--cc=emacs-devel@gnu.org \
--cc=johnw@gnu.org \
--cc=p.stephani2@gmail.com \
--cc=phst@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).