emacs-devel
[Top][All Lists]
Advanced

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

Re: lexical binding?


From: Michael Heerdegen
Subject: Re: lexical binding?
Date: Mon, 25 Oct 2021 14:08:22 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux)

Jean-Christophe Helary <lists@traduction-libre.org> writes:

> What is the issue with using setq on undefined symbols? Can that break
> things eventually?

If you do this, it will soon become impossible to find out
when the values of referenced variables were set and by what code.  Such
a programming style would lead to unreadable and hard-to-debug code.
Not because others are not used to this kind of style - it's really
harder to do.

> Is that related to lexical binding?

Not really.  You have dynamically binding global variables in both the
lexical binding and the dynamically binding dialect of Elisp, and what
you suggest leads to the same problems in both dialects.

OTOH, it is a bit related.  Bindings to lexical variables can be tracked
most easily by a programmer - you can just look at the text to see where
in your code a binding is established.

Dynamical variables are worse, but it's still easy to track dynamical
bindings using a debugger.  You must just look for binding forms
currently processed in the backtrace, and which function called them.

Only using dynamically binding global variables is the most primitive
way of handling computer memory.  Calculators from the 90s had this:
global registers A, ..., Z.  You can't even write recursive functions
using only a limited number of global variables.  And a debugger doesn't
help you much understanding such code.  You must run the complete
program and track set variables to understand what is going on.

So this kind of thing should be avoided wherever possible.

Michael.



reply via email to

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