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

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

Any disadvantages of using put/get instead of defvar?


From: Oleh
Subject: Any disadvantages of using put/get instead of defvar?
Date: Thu, 20 Feb 2014 18:04:52 +0100

Hi all,

I've asked this question on stack overflow and it was suggested that I
ask it here as well.

The situation is that I have a function that uses one global variable.
It's for sure that no other function will want this variable.
In an effort to have all code in one place I want to move from:

    (defvar bar-foo 1)

    ;; bunch of other code

    (defun bar ()
      ;; use bar-foo here
      )

to:


    (defun bar ()
      (let ((foo (or (get 'bar 'foo) 1)))
        ;; use foo here
        ))

So the advantage is that I can move and rename the function
without worry that the function/variable coupling will break,
because now everything is inside one function.

I realize that the variable can still be accessed from outside, but
that doesn't matter much.

One disadvantage listed in the responses was that now the variable
can't be buffer-local any more.

Any other disadvantages to this method?

regards,
Oleh



reply via email to

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