Hey,
If my application is called "Media Player", is it a best practice to name classes: MPSong, MPSinger, MPAlbumsViewController ... ?
views:
64answers:
3All capital two-letter prefixes are reserved by Apple, so you shouldn’t use those. But otherwise there is no definite answer to this question - it’s a matter of personal taste. I personally use a prefix for library classes but not for application classes.
I don't know if the way I name classes is a best practice or not, but if I have a class that is unique to the project I just give it a meaningful name and start with a capital letter. However if it is a class that I intend to reuse I may give it a prefix like the initials of my company or myself so I see the class is meant for reuse.
Another reason for a prefix would be if you have the same name because of similar titling in the same project but have different functionality and run the risk of becoming confusing. For example if you decide to make a class called state as in the state in which you live. Then you wish to create a class called state meaning the current state of you application. It would be a good idea to use a prefix like ADState and APState (AD for address and AP for application). In other frameworks they have namespaces that do the same job.
Apple's Coding Guidelines for Cocoa has lots of advice along these lines.
In short, using a prefix for class and protocol names is encouraged, especially if you're developing a framework. However, Apple already uses the MP prefix for its MediaPlayer framework on the iPhone, so you probably want to pick another.