Private methods in API should always start with underscore
| Originator: | cedric.luthi | ||
| Number: | rdar://10888383 | Date Originated: | 18-Feb-2012 12:17 AM |
| Status: | Duplicate/7424841 | Resolved: | |
| Product: | iPhone SDK | Product Version: | 5.0 |
| Classification: | Serious Bug | Reproducible: | Not Applicable |
Duplicate of rdar://7424841 * Summary: To avoid a repeat of the "Great Add Object If Absent" disaster as described by bbum: http://lists.apple.com/archives/objc-language/2009/Nov/msg00077.html and any similar debacle, all private methods (and functions, for that matter) implemented by Apple should start with an underscore. This, combined with a clearly-defined precedence for original versus category-defined methods, would make adding methods to framework classes by category or by subclass much safer. * Steps to reproduce: Implement a method in a category or subclass whose name happens to be the same as Apple-private API. * Expected results: No selector name collisions. * Actual results: Selector name collisions. * Regression: Every time a private method is added without an underscore prefix, the issue becomes more likely to surface. * Notes: This would have the added benefit of making the case stronger that developers should avoid using underscores for their own private methods!
Comments
Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!
Not that I don't agree, but: always prefix category methods on classes you don't own (e g if yor standard prefix is XY, do -(void)xy_fooBar:(int)baz, not -(void)fooBar:(int)baz). Method might be added in public API in the future, e g.