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?

Drew
  • 75,699
  • 9
  • 109
  • 225
Pedro Delfino
  • 1,369
  • 3
  • 13
  • 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 Apr 28 '22 at 16:48
  • 1
    Some people use the prefix `my-`, since so many people share bits of code. – aadcg May 01 '22 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. – Phil Hudson May 03 '22 at 08:21

1 Answers1

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.

Phil Hudson
  • 1,651
  • 10
  • 13
  • 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 Apr 28 '22 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 – Phil Hudson Apr 28 '22 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 Apr 28 '22 at 20:59