views:

518

answers:

2

Objective-C doesn't have namespaces, and many (such as CocoaDevCentral's Cocoa Style Guide) recommend prefixing your class names with initials to avoid namespace collision.

Quoting from the above link:

Objective-C doesn't have namespaces, so prefix your class names with initials. This avoids "namespace collision," which is a situation where two pieces of code have the same name but do different things.

That makes sense, I suppose. But honestly, in the context of a relatively small app (say, an iPhone game), is this really an issue? Should I really rename MyViewController to ZPViewController? If not, at what point do namespace collisions really become a concern?

+11  A: 

If you're writing an application that uses some set of libraries, then you already know what your namespace looks like and you just need to select names that do not conflict with existing available functions.

However, if you are writing a library for use by others, then you should pick a reasonably unique prefix to try to avoid name collisions with other libraries. With only two characters there may still be name collisions, but the frequency will be reduced.

Greg Hewgill
A: 

Small apps shouldn't use up all the good names, so won't have a problem with namespaces.

But it is a good idea to get used to the style that languages are generally written in. It makes it easier to read other people's code, and for others to read yours.

E. g., use camelCase variables in Java, but CamelCase vars in C#, hyphen_separated_names in C, etc.

It will make it easier for you to learn in the long run.

UncleO