2

Personally, I've never liked the MyObject naming of classes. I would guess that the status quo would agree but I'd like to see the other side of the argument and if there's any validity to it.

Austin Salonen
  • 49,173
  • 15
  • 109
  • 139
  • I'm sure there is some good situation in which this is useful, but I'm with you, I don't like it. Have you ever used a class name like YourObject or HerObject? No, me either. And while we're on the subject, another annoyance is including "Table" in the name of a table. PeopleTable, UserTable, AddressTable, MyFavoritesTable... yuck. The database can tell me what type of object it is. Glad I got that off my chest. – Doug Hays Sep 08 '09 at 16:14
  • I don't really have an opinion in this matter, but will follow this discussion. You say you would like to see the other side of the argument, but you don't supply your argument against this convention, so maybe start there? – staterium Sep 08 '09 at 16:15
  • @Doug - I don't like `SomethingTable` and the like, but isn't there an FxCop or Find-Bugs rule that says that class names should refer to their base class? As is the case with `Map' `List` and `Set` in Java. Gotta look that rule up again. – Brett Ryan Sep 08 '09 at 17:25

6 Answers6

10

'My' is already used by me, use something else

Remus Rusanu
  • 288,378
  • 40
  • 442
  • 569
  • Exactly what I was going to say (but Remus said it better). Unless you're always doing 1-man projects that will never be maintained by anyone else, "My" just isn't very descriptive :-) – Eric J. Sep 08 '09 at 16:16
4

I've never seen it done in production code, although I dare say it exists.

It's like the metasyntactic variables "foo" and "bar" - it's usually used as a placeholder for a real name.

So for example, if I know that someone has their own class deriving from Form, but I don't know anything else about it, a code example would use:

public class MyForm : Form

I'd certainly take a firm stance against it for real code though :)

Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194
3

I suppose one instance where it would be close to acceptable is if the class you're prefixing with "My" is an inner class (i.e a private class declared within another class). I'm not sure if there are any naming conventions governing inner classes, but this could be one way to differentiate.

Mark Carpenter
  • 17,445
  • 22
  • 96
  • 149
1

As far as I've ever seen, My is a prefix used in sample code that indicates "your stuff goes here".

It's kind of like foo. Teaching purposes only.

Ken
  • 12,933
  • 4
  • 29
  • 32
0

I've used My in 2 situations:

  1. Way back when in my first programming classes in school
  2. When I am doing basic 'hello world' applications to learn a language

but NEVER in production or even pseudo-production code.

Badfish
  • 269
  • 1
  • 4
0

I'd avoid it in production code, your type name should reflect the function its supposed to perform.

I've used it a couple of times when patching/hacking third party code, for instance replacing Controller with MyController to make it clear it is a hack, that should be approached with caution, and a bat.

Rich Seller
  • 83,208
  • 23
  • 172
  • 177