It comes from small, trivial pieces of code used in programming examples when there is no context and the actual purpose of the variable is irrelevant.
var myThing = new Thing()
The only two important aspects of the variable myThing is that it is an instance of Thing, and that "I" created it. It has no purpose and no meaning apart from that, so it is impossible to give it a meaningful name. Calling it "myThing" draws attention to its only two important aspect. In that sense the name is (minimally) meaningful.
That's the historical reason.
However because of this, and the lack of any meaningful information conveyed by the name about content or use, the use of my* variables should be entirely restricted to programming examples. Any use in a production environment should be shunned, and anybody who practices it there should be beaten with sticks and sent on a remedial programming course.
In the example above a professor is highly likely to be giving students programming examples and its use is fine there. Anywhere else it is anathema.
class MyClass
,void MyFunction()
,int myInt;
etc, are a great way to avoid using metaphorical names and contrived examples which might initially appear to be "real-world-related" but instead end up conveying completely the wrong semantics that actually mislead and confuse the reader. For example, articles which use names likeVehicle
orAnimal
frequently cause all kinds of confusion when readers start to take the metaphors literally and simply causes confusion when readers end up focusing more on the metaphor rather than the programming concepts.m_
or_
- a form (and a relic) of at one time widely spread Hungarian notation. I'm guessing there are people who are usingmy
as a variant of this (where, in methods, "my" indicates the object is referring to a variable it owns).