1. This forum is obsolete and read-only. Feel free to contact us at support.keenswh.com

'My' prefix for classes and interfaces

Discussion in 'Modding API' started by Harag, Jan 13, 2015.

Thread Status:
This last post in this thread was made more than 31 days old.
  1. Harag

    Harag Junior Engineer

    Messages:
    913
    I was just wondering. Why does every class and interfaces of the ModAPI start with the prefix My?

    Certainly the class is not mine, it's Keen's.
    Instances of the class are mostly not mine, either. They belong to the world my script is running in.
    When I write a class of my own should I name it ReallyMyClass? Or MYClass, maybe?
    What is someone who is not me supposed to name his classes?

    ...no, I'm not exactly serious, but I'd be interested in the rationale to choose that prefix ;)
     
  2. CptTwinkie

    CptTwinkie Master Engineer

    Messages:
    4,458
    This is just how I've seen it used. If someone knows better please correct me.

    In my experience the prefix My is used with object oriented programming as a handy naming convention. Any class that's meant to instantiate an object is named with a My prefix since you'll be using it to create objects for your own use. The properties in an object class are also prefixed with My. I think this is the origin of the naming convention. When I was learning programming over a decade ago we used the underscore "_" to prefix argument names in functions that matched variable names outside of the functions. That way we didn't mix them up and use them out of scope. I think it's much the same with My properties inside of methods.

    In summary I would say that you should name your classes and properties any thing you want. When it starts getting confusing and you need to remember which is which you'll probably end up using the My prefix because it's short and easy.
     
  3. Xentor

    Xentor Junior Engineer

    Messages:
    869
    It's a little bit odd, to be sure. I've been programming for a long time, and the only time I've ever seen the "My" prefix was back in the Visual Basic days, when they were trying to make it friendly to novices.

    I would guess that the "My" prefix is an artifact of when they first designed the API (Maybe it was to distinguish between the script's objects and the game's objects). After a redesign or two, the name could have stuck... Then they just keep it for consistency.

    It could also just be a language thing... Keen is in Prague, right?
     
  4. BlueG

    BlueG Apprentice Engineer

    Messages:
    119
    My experience is like yours, lttwinkie, but I first started with m or hungarian notation, then went to the underscore, then my, and now I do whatever strikes me at the moment it seems. But then, I think a large part of that was because I was a C++, C# programmer, but then had to start using VB, then returned to C#. Now I find that in my personal programming, I'll often use my for instance variables (as opposed to class variable (static) or method variables).
     
  5. CptTwinkie

    CptTwinkie Master Engineer

    Messages:
    4,458
    I forgot about m. That one was confusing because I always saw it used for passing variables. I always figured it was more like how everyone uses i to name their iterators. It's just habbit.

    I went from basic to vb to c++ to html/css to JavaScript to Java/Android. I can't say I've stuck with any of them for long but they all have their twist on things.
     
  6. midspace

    midspace Senior Engineer

    Messages:
    2,224
    From what I understand, "My" was always used in code samples in Visual Basic as a place holder.
    The idea was to replace "My" with a shortened version of your application or company name, making it very clear whos code it was.

    Namespaces in .Net make this redundant, thus you don't often find such names in classes in DotNet code these days.

    I'm guessing from Keen's perspective, it kind of stuck and their wasn't any need to change it.

    Personally I don't see any need to use My in your own code, unless you are attempting to write a custom cube block with the backing code, in which case replicating the naming conventions of Keen's code will help reduce confusion when developing and debugging it.
     
    Last edited by a moderator: Jan 18, 2015
  7. Harag

    Harag Junior Engineer

    Messages:
    913
    So to summarize it's fair to call it a habit best to avoid because it serves no purpose nowadays.
     
    Last edited by a moderator: Jan 18, 2015
Thread Status:
This last post in this thread was made more than 31 days old.