0

I think back to many tutorials and code snippets in which I have seen variables, functions, and files with "my" or "my_" prepended. What is the origin of this convention?

14
  • 5
    The origin of this convention is English grammar providing possessive pronouns to indicate the desired semantics in a mnemonic way. Perhaps, you mean "what was the earliest known publication using that convention"? If so, please edit your question for clarity.
    – Leo B.
    Nov 4, 2021 at 1:49
  • 8
    Editorial ‘we’ is pretty standard, it’s nothing exclusive to code comments. Nov 4, 2021 at 5:56
  • 6
    It's not a convention, it's just the author of that tutorial telling you that this is your/their own version of it. It's often used to differentiate a standard library function from your own implementation (strlen vs. my_strlen) Nov 4, 2021 at 11:39
  • 5
    The correct names to use for example variables are 'foo', 'bar', and 'mumblefrotz'.
    – dave
    Nov 4, 2021 at 11:56
  • 3
    @another-dave I don't know where mumblefrotz comes from and I've never heard it before. The pseudo-standard for the third metasyntactic variable in the sequence is "baz"... but thanks for making me refresh my memory. I've been skipping over "qux" and going straight to "quux" for number 4 for years. Likewise, for Python, I was using the de facto standard ones incorrectly by skipping from "spam" to "eggs" without going through "ham".
    – ssokolow
    Nov 6, 2021 at 6:49

1 Answer 1

1

Origin? ...I think that comes from simple human interest in taking topics out of the specific and into a more general context, in that, at least when I do this myself (which is mostly every time I share ANY code in a public forum), I, as the old Dragnet TV program used to say "change the names to protect the innocent." It's not any more complicated than that!

This is ESPECIALLY true of people asking questions in the Stack Exchange community: MOST of us work in environments where whatever we're working on is at least SOMEWHAT concerned about privacy; we don't want to inadvertently, much less intentionally, share information that we may very well have non-disclosure agreements covering! This could be code we're writing for a client or for a corporation, etc...

Don't over-think it!

2
  • This is asking about a naming convention found within documentation, which is generally public, so the tangent about NDAs is mostly irrelevant. And the rest is armchair speculation. Aug 8, 2022 at 13:39
  • @user3840170 Speculation? Surely. But, first, you apparently overlooked my initial paragraph and focused on the second. And ... where do you think documentation comes from? Hint: Mostly it's from engineers / code developers who actually perform the work, and, even when written by professional writers they get a LOT of documentation material from engineers who provide them examples... Speaking from experience, I am not wrong, however, it's SURELY speculative what "origins" were. And, I directly said the NDA issue often applies to Stack Exchange-like sites.
    – Richard T
    Aug 8, 2022 at 19:19

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .