[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Symbols or strings as arguments
From: |
Tassilo Horn |
Subject: |
Re: Symbols or strings as arguments |
Date: |
Thu, 28 Nov 2024 06:36:10 +0100 |
User-agent: |
mu4e 1.12.7; emacs 31.0.50 |
Heime via Users list for the GNU Emacs text editor <help-gnu-emacs@gnu.org>
writes:
> I wonder whether developers would preferentially use symbols rather
> than strings in arguments.
>
> Consider calling (cupola '(72 tabtrail local)) versus (cupola '(72
> "tabtrail" "local"))
Obviously, it depends. If the arguments are essentially an enumeration,
i.e., the possible/allowed values are just a small set, then I'd use
symbols or keywords. E.g., an argument location with possible values
local and remote => :local / :remote. An argument first-name, well,
that's a string because it can be anything.
It also depends on the usage of the argument. If you just print it out,
a string is fine. If you dispatch on it (using case, pcase, cond),
keywords and symbols are probably better. Mostly because they stand out
a bit and it's immediately visible that they have special meaning
affecting the control flow.
Bye,
Tassilo