[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Naming predicates
From: |
Stefan Monnier |
Subject: |
Re: Naming predicates |
Date: |
Fri, 28 Sep 2018 15:26:24 -0400 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) |
>> If the purpose of a function is to tell you whether a certain
>> condition is true or false, give the function a name that ends in
>> 'p' (which stands for "predicate"). If the name is one word, add
>> just 'p'; if the name is multiple words, add '-p'. Examples are
>> 'framep' and 'frame-live-p'.
*Users* should never define a single-word function, since they should
use a namespace prefix. Hence "I'd say you can simply always use "-p"
when it's something you define".
> Thanks for the pointer; I'd forgotten that. But there are several
> counterexamples:
You don't have to follow them when you define your own function.
> indivisible-p interactive-p ring-p registerv-p
> bool-vector-subsetp coding-system-lessp default-boundp file-attributes-lessp
> hack-one-local-variable-eval-safep ...
Yes, there are conflicting desires: when you define something that's
very much like "foop" but in the context of "strigles", the multi-word
rule suggest you name it "strigle-foo-p", but there's also an argument
to be made for "strigles-foop".
As the author of that function you get to follow whichever of the two
you like. Personally, I think always using "-p" is a simpler rule and
is never wrong (that's the rule followed by `cl-defstruct`,
incidentally). Even using "-p" on single-word thingies is
perfectly acceptable.
> The Common Lisp influence seems to be causing a lot of Elisp code to violate
> the guideline, which may help to explain why I can never remember it.
While the inconsistency is annoying when trying to reference an existing
function, the situation is much simpler when you're defining a new
function.
Stefan
- Re: master d0c77a1: Remove some assumptions about timestamp format, (continued)
- Re: master d0c77a1: Remove some assumptions about timestamp format, Paul Eggert, 2018/09/28
- Re: master d0c77a1: Remove some assumptions about timestamp format, Michael Albinus, 2018/09/28
- Re: master d0c77a1: Remove some assumptions about timestamp format, Paul Eggert, 2018/09/27
- Re: master d0c77a1: Remove some assumptions about timestamp format, Michael Albinus, 2018/09/28
- Re: master d0c77a1: Remove some assumptions about timestamp format, Paul Eggert, 2018/09/28
- Naming predicates (was: master d0c77a1: Remove some assumptions about timestamp format), Stefan Monnier, 2018/09/28
- RE: Naming predicates (was: master d0c77a1: Remove some assumptions about timestamp format), Drew Adams, 2018/09/28
- Re: Naming predicates (was: master d0c77a1: Remove some assumptions about timestamp format), Paul Eggert, 2018/09/28
- Re: Naming predicates,
Stefan Monnier <=
- RE: Naming predicates, Drew Adams, 2018/09/28
- RE: Naming predicates (was: master d0c77a1: Remove some assumptions about timestamp format), Drew Adams, 2018/09/28