Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are namespace collisions really an issue in Objective-C?

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?

like image 315
zpasternack Avatar asked Jun 20 '09 05:06

zpasternack


1 Answers

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.

like image 104
Greg Hewgill Avatar answered Oct 27 '22 13:10

Greg Hewgill