unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Emanuel Berg via Users list for the GNU Emacs text editor <help-gnu-emacs@gnu.org>
To: help-gnu-emacs@gnu.org
Subject: Re: Understanding the "let" construct and the setting of variables
Date: Sat, 19 Dec 2020 07:23:55 +0100	[thread overview]
Message-ID: <875z4ye2kk.fsf@zoho.eu> (raw)
In-Reply-To: X9zxAPY/m8d+WAyw@protected.rcdrun.com

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




      parent reply	other threads:[~2020-12-19  6:23 UTC|newest]

Thread overview: 50+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-17  0:10 Understanding the "let" construct and the setting of variables steve-humphreys
2020-12-17  0:21 ` Joost Kremers
2020-12-17  2:08   ` steve-humphreys
2020-12-17  3:12     ` steve-humphreys
2020-12-17  8:01       ` Joost Kremers
2020-12-17  8:31         ` steve-humphreys
2020-12-17  8:50           ` Joost Kremers
2020-12-17  8:10     ` Joost Kremers
2020-12-17  8:43       ` steve-humphreys
2020-12-17  8:56         ` Joost Kremers
2020-12-18 20:48           ` Emanuel Berg via Users list for the GNU Emacs text editor
2020-12-18 20:46         ` Emanuel Berg via Users list for the GNU Emacs text editor
2020-12-18 21:07           ` Jean Louis
2020-12-18 22:31           ` tomas
2020-12-18 20:39       ` Emanuel Berg via Users list for the GNU Emacs text editor
2020-12-17  2:49   ` steve-humphreys
2020-12-17  7:58     ` Joost Kremers
2020-12-17 16:55       ` Drew Adams
2020-12-17 20:11         ` steve-humphreys
2020-12-17 21:57           ` Drew Adams
2020-12-17 22:35           ` Michael Heerdegen
2020-12-18  9:01             ` tomas
2020-12-18  9:16               ` Michael Heerdegen
2020-12-18 20:55                 ` Emanuel Berg via Users list for the GNU Emacs text editor
2020-12-19  2:17                   ` Michael Heerdegen
2020-12-19  2:52                     ` Drew Adams
2020-12-19  5:15                     ` Stefan Monnier
2020-12-18 20:33   ` Emanuel Berg via Users list for the GNU Emacs text editor
2020-12-17  0:25 ` steve-humphreys
2020-12-17  0:35   ` steve-humphreys
2020-12-17  1:05     ` Joost Kremers
2020-12-17  1:20       ` steve-humphreys
2020-12-18 20:58         ` Emanuel Berg via Users list for the GNU Emacs text editor
2020-12-17  4:34   ` Jean Louis
2020-12-17  5:12     ` steve-humphreys
2020-12-19  6:06       ` Emanuel Berg via Users list for the GNU Emacs text editor
2020-12-17  7:31     ` steve-humphreys
2020-12-19  5:55     ` Emanuel Berg via Users list for the GNU Emacs text editor
2020-12-19  6:49       ` Jean Louis
2020-12-20  5:19         ` Emanuel Berg via Users list for the GNU Emacs text editor
2020-12-18 17:14   ` Emanuel Berg via Users list for the GNU Emacs text editor
2020-12-18 17:48     ` tomas
2020-12-18 15:33 ` Emanuel Berg via Users list for the GNU Emacs text editor
2020-12-18 18:12   ` Jean Louis
2020-12-18 18:20     ` Drew Adams
2020-12-18 18:45       ` Jean Louis
2020-12-18 19:16         ` Drew Adams
2020-12-18 20:00           ` Jean Louis
2020-12-18 21:27     ` Christopher Dimech
2020-12-19  6:23     ` Emanuel Berg via Users list for the GNU Emacs text editor [this message]

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=875z4ye2kk.fsf@zoho.eu \
    --to=help-gnu-emacs@gnu.org \
    --cc=moasenwood@zoho.eu \
    /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.
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).