[m-users.] IO and global state.

Zoltan Somogyi zoltan.somogyi at runbox.com
Mon Apr 26 16:36:40 AEST 2021



On Mon, 26 Apr 2021 07:16:52 +0100, "Sean Charles (emacstheviking)" <objitsu at gmail.com> wrote:
> Is it a —wise— idea to consider using globals on the IO State?

We initially thought so, and wrote the compiler that way.

We later realized that beyond a certain complexity, it was simply
less error-prone to pass the globals explicitly to every part of the code
that needed it, even though it required writing more code.
The compiler now consistently passes the globals *separately*
from the I/O state, except maybe in the very initial startup code.
(I don't know for sure, I haven't looked at that code in a long time.)

The problem with consistently storing the globals in the I/O state
is debugging. When you are looking at a call that updates the
I/O state, you cannot be certain whether that call also updated
the globals, unless you inspect both the callee *and its entire
call tree*. In a small program, that is not too much of a burden;
in a large program, it is. Getting such things wrong can cause bugs
that are annoyingly hard to track down. Writing explicit code
to pass the globals is a tiny bit of extra work in the usual case,
but can save a lot unpleasant debugging.

So the answer to your question is: if you are sure that your program
will always remain small, then yes; otherwise, no.

Zoltan.



More information about the users mailing list