objective-c: good and bad

Download Objective-C: Good and Bad

If you can't read please download the document

Upload: anthony-shoumikhin

Post on 26-May-2015

1.431 views

Category:

Technology


3 download

TRANSCRIPT

  • 1. Objective-C: Good and Bad

2. Good 3. LighweightSimply preprocessor and small runtimeSyntax sugar over C, easy to learn 4. RuntimeCompletely dynamic message sending. Dont need inheritance to call a method with different objectsTrue introspection. Allows to watch classhierarchy, check if an object has aparticular invariant or implements somemethod, call a method by name 5. Categories and ProxiesAllows addition of methods to another classEven a class you dont have source forAlso allows overriding of existing methods 6. Key Value Coding/ObservingBind string names with object invariants atrun-timeCall back when the value of some invariant is going to be / was changed 7. Self-contained objectsObjects tend to be handful and smart enough to be used standalone 8. #importNo include guards or #pragma once anymore 9. [NSBundle classNamed]Create a class by name, which could be used later to instantiate objects 10. BlocksClosures are awesomeAllows to define a block of code withsurrounding context and pass it to otherfunctionFacilitates concurrency 11. Bad 12. SyntaxLots of square braces. Compare:[[[MyClass alloc] init:[foo bar]] autorelease]MyClass.alloc.init(foo.bar).autoreleaseKeyed parameters: difficult to reorder them during refactoring 13. LighweightThe same code has to be repeated oftenLittle language support for anything otherthan message sendingFolks could say because theres no magic. But more code means more bugsWithout Cocoa this no magic would be absolutely awful 14. Memory ManagementHalf-manual, half-automaticRaw pointers are evilNo garbage collectorReference counters overheadMigration to automatic reference counting takes time 15. Allocation and InitializationWhich are two separated operations MyClass *object = [MyClass alloc] init];Multiple constructors work via designated initializers without any language supportself = [super init]; //assignment to self :(if (self){//init invariants}return self; 16. No Stack ObjectsDealloc wont be called automatically 17. Messaging nilDoes nothing and hides real bugsWouldnt be so bad if it were easy to make messaging nil screamCocoa messages nil as a matter of course 18. Overriding and OverloadingCategories are broken: overriding a method more than once leads to undefined behaviorNo method overload. Need to mangle names manually 19. No NamespacesNot a major gripe, but Its real handy 20. Id should be id *Not clear: NSString *foo = @foo; id bar = foo;Better: NSString *foo = @foo; id *bar = foo; 21. So So 22. FrameworksCould be a problem, if Cocoa wasnt the best one publicly available 23. Type SafetyCant catch lots of errors during the compile timeBut allows its awesome runtime features 24. Questions?