4

Is it a namespace trick to prevent future problems?

I noticed a pattern in the Emacs community. When people create some tailor made function and insert it on their init files, they use a convention on the name prefixing it with their initials.

For instance, take a look on this question that I previously asked. The answer is:

  (defun ndk/org-clock-sum-current-region (beg end)
     (interactive "r")
     (let ((s (buffer-substring-no-properties beg end)))
       (with-temp-buffer
         (insert "* foo\n")
         (insert s)
         (org-clock-sum)
         (message (format "%d" org-clock-file-total-minutes)))))

It was written by the great user NickD. Thus, he used ndk (k must come from an unknown last name).

I believe this not an aesthetic effort. At least, not only aesthetic.

This seem to be some sort of "good practice". But I do not see the point. I might be missing something.

Technically, what is the point of doing that? Why not just calling the function org-clock-sum-current-region? What could you lose doing that?

3
  • 1
    Since you accepted @PhilHudson's answer, which says nothing about why people use their initials as a function-name prefix or whether doing that is an Elisp convention, please consider editing your question to make clear that you're not asking that - you're apparently asking only why a function name is commonly prefixed (in some way that's irrelevant to what the function does). That will help people find this Q&A.
    – Drew
    Commented Apr 28, 2022 at 16:48
  • 1
    Some people use the prefix my-, since so many people share bits of code.
    – aadcg
    Commented May 1, 2022 at 15:58
  • 2
    Indeed (or my/). As @aadcg notes, that's a way to make your code easily shareable. I almost always adapt such code in one way or other to my own style and idioms, and if I do so I always rename with my initials but put a link to the original in a comment, so if I pass my version on the originator still gets their due credit. Creator acknowledgement is the lifeblood of freedom-respecting software. Commented May 3, 2022 at 8:21

1 Answer 1

8

It's a workaround for a misfeature of elisp: no namespaces. Its main purpose is to prevent name collisions for code written by different users/provided by different packages. It secondarily helps those of us who write a lot of our own code to know when we need to blame ourselves.

3
  • 2
    This answer says why a prefix is added. It doesn't say why people add their initials as such a prefix, or whether doing that is actually an Elisp convention.
    – Drew
    Commented Apr 28, 2022 at 16:45
  • 1
    I had a feeling there was more to say... unfortunately I don't feel qualified to give a definite answer on either of those beyond my attempt above. I'd be interested and appreciative if you gave a fuller one, @Drew Commented Apr 28, 2022 at 19:57
  • 1
    I think your answer is fine. It's the question that should be edited, to match the answer that was accepted, i.e., framed without mention of personal initials etc. If it weren't accepted then I'd say the question is fine and the answer is good but incomplete, which is fine (which is the answer comment I left here, before I added the question comment).
    – Drew
    Commented Apr 28, 2022 at 20:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.