help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Understanding the "let" construct and the setting of variables


From: Emanuel Berg
Subject: Re: Understanding the "let" construct and the setting of variables
Date: Sat, 19 Dec 2020 07:23:55 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)

Jean Louis (and I) wrote:

>> 3. if that isn't enough to use let/let* because several
>>    functions need to access a variable, use `setq' at the
>>    base level (i.e., first char of the line, or column 0) -
>>    not that Elisp has only one level, really, which is why

That should be NOTE, not "not". By that I mean a file, even
a package does not have its own namespace. Everything defined
is accessible from everywhere.

>>    you should use `setq' there to avoid confusion and
>>    errors. Because everyone can see what is created by
>>    `setq', this should be visible in the code style
>>    as well.

By this I mean, do it like this:

(defvar some-var)
(setq some-var some-value)

Joe Elisp Hacker then immediately thinks, "alright, a global
var". And he'd be right!

But do it like this:

(defun some-function ()
  (setq some-var some-value) )

it is "hm, is this a global variable? it could be, if the
function was called. was it? or did the programmer forgot to
put it in the let varlist? is it thus a bug? or is it defined
in some other file? or [etc]"

so to remove all doubt, create global vars like the first
example. And do this only when let for some specific reason
isn't enough.

> Instructions like that belong on a website where they become
> easily searchable for other users to understand it.

Yeah, but to be honest ... don't everyone know that you should
avoid global variables? I think that was among the first thing
I learned as a programmer at age 12 or something (and I was
truly a _horrible_ programmer then, and it didn't stop at 12 -
but yeah, how could one be anything else at that point...).

But everyone should understand it, really. It is just like
putting gear in a toolbox. One box for fishing gear and one
for bike repairs (yep, that'd be a big one). And nothing that
has to do with fishing or bikes just lying around on the
floor, for every goofball that treads it to trip on or pick up
and fiddle with...

> We could index all the mailing list easily and provide
> search engine for this.

Well, they are archived and searchable, of course! See:

  http://lists.gnu.org/archive/html/help-gnu-emacs/

-- 
underground experts united
http://user.it.uu.se/~embe8573
https://dataswamp.org/~incal




reply via email to

[Prev in Thread] Current Thread [Next in Thread]