* defvar vs defconst
@ 2013-08-02 9:49 Thorsten Jolitz
2013-08-02 21:49 ` Stefan Monnier
2013-08-03 3:37 ` Eric Abrahamsen
0 siblings, 2 replies; 5+ messages in thread
From: Thorsten Jolitz @ 2013-08-02 9:49 UTC (permalink / raw)
To: help-gnu-emacs
Hi List,
when you define a variable that should not be touched/set by the user of
your library (which is most likely a programmer), but will be frequently
set to a new value by your own program - would you call that a VAR or a
CONST?
(defconst ...) signals "don't touch this", which seems to the right
thing in this case, but OTOH it is a bit strange to call something a
constant that not only can be changed, but will actually be changed
quite often.
--
cheers,
Thorsten
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: defvar vs defconst
[not found] <mailman.2402.1375476850.12400.help-gnu-emacs@gnu.org>
@ 2013-08-02 21:05 ` Emanuel Berg
0 siblings, 0 replies; 5+ messages in thread
From: Emanuel Berg @ 2013-08-02 21:05 UTC (permalink / raw)
To: help-gnu-emacs
Thorsten Jolitz <tjolitz@gmail.com> writes:
> (defconst ...) signals "don't touch this", which seems to the
> right thing in this case, but OTOH it is a bit strange to call
> something a constant that not only can be changed, but will
> actually be changed quite often.
A constant should not be changed, not by a human, and not by a
computer, either. This is my firm intuition.
#00FF00 for green and #FFFF00 for yellow; 3.1415... for PI;
etc. This is the stuff you always make constants of.
number_of_attempts *could* be a constant, because once set, it
would never be changed in an execution run, and actually not at
all, unless there is a policy decision to change the number of
attempts. Still, I'd prefer it a variable.
In your particular case, I don't know. Are there different
implications using the methods, if you don't consider what signals
they send to a human user?
--
Emanuel Berg - programmer (hire me! CV below)
computer projects: http://user.it.uu.se/~embe8573
internet activity: http://home.student.uu.se/embe8573
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: defvar vs defconst
2013-08-02 9:49 defvar vs defconst Thorsten Jolitz
@ 2013-08-02 21:49 ` Stefan Monnier
2013-08-03 3:37 ` Eric Abrahamsen
1 sibling, 0 replies; 5+ messages in thread
From: Stefan Monnier @ 2013-08-02 21:49 UTC (permalink / raw)
To: help-gnu-emacs
> set to a new value by your own program - would you call that a VAR or a
> CONST?
defconst should be used for things which don't change, so I'd call it a VAR.
Stefan
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: defvar vs defconst
2013-08-02 9:49 defvar vs defconst Thorsten Jolitz
2013-08-02 21:49 ` Stefan Monnier
@ 2013-08-03 3:37 ` Eric Abrahamsen
2013-08-03 7:43 ` Thorsten Jolitz
1 sibling, 1 reply; 5+ messages in thread
From: Eric Abrahamsen @ 2013-08-03 3:37 UTC (permalink / raw)
To: help-gnu-emacs
Thorsten Jolitz <tjolitz@gmail.com> writes:
> Hi List,
>
> when you define a variable that should not be touched/set by the user of
> your library (which is most likely a programmer), but will be frequently
> set to a new value by your own program - would you call that a VAR or a
> CONST?
>
> (defconst ...) signals "don't touch this", which seems to the right
> thing in this case, but OTOH it is a bit strange to call something a
> constant that not only can be changed, but will actually be changed
> quite often.
In addition to the other answers, which make perfect sense, you can also
look in existing libraries and see what other people do. I've found that
pretty much all "internal" variables -- last-abbrev-location,
org-capture-current-plist, basically any variables used to preserve
state -- are defined with defvar.
HTH,
Eric
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: defvar vs defconst
2013-08-03 3:37 ` Eric Abrahamsen
@ 2013-08-03 7:43 ` Thorsten Jolitz
0 siblings, 0 replies; 5+ messages in thread
From: Thorsten Jolitz @ 2013-08-03 7:43 UTC (permalink / raw)
To: help-gnu-emacs
Eric Abrahamsen <eric@ericabrahamsen.net> writes:
> Thorsten Jolitz <tjolitz@gmail.com> writes:
>
>> Hi List,
>>
>> when you define a variable that should not be touched/set by the user of
>> your library (which is most likely a programmer), but will be frequently
>> set to a new value by your own program - would you call that a VAR or a
>> CONST?
>>
>> (defconst ...) signals "don't touch this", which seems to the right
>> thing in this case, but OTOH it is a bit strange to call something a
>> constant that not only can be changed, but will actually be changed
>> quite often.
>
> In addition to the other answers, which make perfect sense, you can also
> look in existing libraries and see what other people do. I've found that
> pretty much all "internal" variables -- last-abbrev-location,
> org-capture-current-plist, basically any variables used to preserve
> state -- are defined with defvar.
Pretty clear picture - I will use 'defvar then. Thanks to everybody.
--
cheers,
Thorsten
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2013-08-03 7:43 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-08-02 9:49 defvar vs defconst Thorsten Jolitz
2013-08-02 21:49 ` Stefan Monnier
2013-08-03 3:37 ` Eric Abrahamsen
2013-08-03 7:43 ` Thorsten Jolitz
[not found] <mailman.2402.1375476850.12400.help-gnu-emacs@gnu.org>
2013-08-02 21:05 ` Emanuel Berg
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.