Language (programming language) wars are overrated.
As a professional/career software engineer, it is our job to learn fast, evolve and continually grow in the context of different languages and software paradigms.
Learning Objective-C and iOS cocoa touch framework isn't as scary as people purport it to be. Ignore the critics, trust in your own abilities and dive into Objective-C if you need to build a mobile app for your company. Today.
2. About Me
@calvinchengx
• Chemical engineering from NUS
• Scientific Freezer Engineer for a local company
• Started my own software company, small team of 5 + some
interns
• Learned programming and web development along the way
• (web) appify scientific projects with universities
• Various consumer web apps python/django
• Attempted my own product start-up(s) including an app with
PhoneGap
• Currently working on an academic conference web app as a
product start-up, serving 3-4 conferences so far
6. “Twas well observed by Lord Bacon, That a little
knowledge is apt to puff up, and make men giddy,
but a great share of it will set them right, and bring
them to low and humble thoughts of themselves.
Anonymous, A B (16th century)
15. WHY THIS MATTERS?
• Split 10,000 hours into very small projects/parts-of-a-big-project
• Push your boundary for each project and learn
• Learning != Muscle Memory
• Practice
16. Peter Norvig
tl;dr
• Get interested
• Program
• Talk with other programmers
• Work with other programmers
• Work after other programmers
• Learn at least 6 languages
• Figure out computer instruction execution, disk, memory
• Learn language standardization
• Get out from language standardization
17. Getting started with iOS/Objective-C
• Read blog posts and books; download and play with iOS apps
• Program with Tutorials; and your own creations
• Talk with people on http://facebook.com/groups/iosdevscout
• Work with colleagues or hack-alongs @ iOS Dev Scout meet-ups
• Work after iOS open source libraries on http://github.com
• Learn at least Python, Javascript (jQuery), golang, C, clojure (etc)
• Understand pointers/memory management, multi-threading etc
• Read best practices, learn programming methodologies, XP,
TDD, CI, CD and practice UI/UX.
• Repeat
18. Key Concepts in Objective-C & iOS
• Superset of C
• Message passing (small talk/obj-c) versus Method calls (c/c++)
• Delegation versus Inheritance
20. • The difference between message passing and calling a
method is in the linking.
• c and c++ the function calls are linked at compile time
with the linker (except with virtual functions which
requires some runtime support).
• objective-c and smalltalk, you cannot guarantee what
functions will be run until runtime. The runtime
determines if an object actually implements the function
represented in the message. If it doesn't implement it, the
class will usually either forward the message onto another
object, or throw an exception.
21. • Overall, a message is the same thing as calling a
method directly, except the runtime finds the exact
function to be called instead of it being linked at compile
time.
22. Delegation
The real reason that you'd want to use delegation is that
the class you were designing has some resemblance to
another class, but isn't really enough like it that you'd call it
the same kind of thing.
23. Delegation
In c++, the only delegation that make sense is when you
are is a service (words ending with 'er', 'or', 'tory',
example HTMLLexER, JSONParsER, PrettyPrintER).
That is exactly what delegation sounds like. Delegating a
task to an expert class. (This could also result because the
lack of support for traits)
- Don Han
25. Delegation: An Example
@protocol CLLocationManagerDelegate<NSObject> Built-in iOS
@optional
/*
* locationManager:didUpdateToLocation:fromLocation:
*
* Discussion:
* Invoked when a new location is available. oldLocation may be nil if there is no previous location
* available.
*/
- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation;
...
@end
26. Delegation: An Example
Our Custom
class/object
// CurrentLocationViewController.h
// implements CLLocationManagerDelegate protocol
(be a delegate!)
#import <UIKit/UIKit.h>
#import <CoreLocation/CoreLocation.h>
@interface CurrentLocationViewController : UIViewController <CLLocationManagerDelegate>
....
@end
28. Delegation: An Example
Our Custom
class/object
(be a delegate!)
...
- (void)startLocationManager
{
if ([CLLocationManager locationServicesEnabled]) {
locationManager.delegate = self;
locationManager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters;
[locationManager startUpdatingLocation];
updatingLocation = YES;
[self performSelector:@selector(didTimeOut:) withObject:nil afterDelay:60];
}
}
...
29. Delegation: An Example
Our Custom
class/object
(be a delegate!)
...
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:
(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
NSLog(@"didUpdateToLocation %@", newLocation);
if ([newLocation.timestamp timeIntervalSinceNow] < -5.0) {
return;
}
if (newLocation.horizontalAccuracy < 0) {
return;
} In CLLocationManagerDelegate.h
// This is new
CLLocationDistance distance = MAXFLOAT;
if (location != nil) {
distance = [newLocation distanceFromLocation:location];
}
...
30. Delegation: An Example
Built-in iOS
@protocol CLLocationManagerDelegate<NSObject>
@optional
/*
* locationManager:didUpdateToLocation:fromLocation:
*
* Discussion:
* Invoked when a new location is available. oldLocation may be nil if there is no
previous location
* available.
*/
- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation;
31. Takeaway:
Not much use cases for subclass-ing.
Think in terms of
composition & delegation to
“specialized” pre-written code
32. Resources: iOS
• iOS Dev Scout
• iTunes University (Stanford, Paul Hegarty)
• Ray Wenderlich (Tutorials, Free & Paid)
• https://github.com/calvinchengx/BullsEye
• https://github.com/calvinchengx/Checklists
• https://github.com/calvinchengx/Calculator
• https://github.com/calvinchengx/MyLocations3
• https://bitbucket.org/calvinchengx/foloup2
A small amount of knowledge can mislead people into thinking that they are more expert than they really are. The &#x201C;learning version&#x201D;.\n
A B, predating Alexander Pope, the &#x201C;Knowledge version&#x201D;.\n
Life is short, [the] craft long, opportunity fleeting, experiment treacherous, judgment difficult.\n
\n
\n
\n
\n
Growth mindset\n
Growth mindset\n
\n
In the video, Derek Sivers talk about a study where 2 classes are conducted in 2 different manners.\n\nMany small claypots (quantity-and-practice focused) versus Make 1 good claypot (quality-and-single-grade-approach).\n
\n
\n
http://stackoverflow.com/questions/5451926/is-message-passing-in-small-talk-and-objectivec-same-as-calling-method-with-valuOnce the actual function call is made, there is no difference. The difference between message passing and calling a method is in the linking. For languages like c and c++ the function calls are linked at compile time with the linker (except with virtual functions which requires some runtime support). With languages that use a messaging system like objective-c and smalltalk, you cannot guarantee what functions will be run until runtime. The runtime determines if an object actually implements the function represented in the message. If it doesn't implement it, the class will usually either forward the message onto another object, or throw an exception. However, if the class does implement it, the runtime determines the address of the actual function, and calls it in the exact same manner as c (pushing the arguments and the return address onto the stack).\nOverall, a message is the same thing as calling a method directly, except the runtime finds the exact function to be called instead of it being linked at compile time.\nhttp://stackoverflow.com/questions/2068158/why-does-cocoa-use-delegates-rather-than-inheritance\nWith delegates, you can have one object be the delegate of many other objects. For example, you can have your MyController instance be the delegate of an NSTableView, an NSTextField, an NSWindow, and any other objects that compose your interface. This gives a compact place to put all of your user interface code related to one section of your UI.\nIf you'd done that with subclassing, you'd have to create one subclass every object you wanted callbacks from.\nNot only does delegation in C++ and Java mean writing more code, it is also not as performant as class inheritance. Implicit delegation by inheritance needs constant time, explicit delegation is linear.\n\nIn Python (and of course Objective-C), delegation can be achieved with as little as one extra method to delegate to one or more classes. Altering the number of parameters of a delegated method often requires a change to only one module.\n\n
http://stackoverflow.com/questions/5451926/is-message-passing-in-small-talk-and-objectivec-same-as-calling-method-with-valuOnce the actual function call is made, there is no difference. The difference between message passing and calling a method is in the linking. For languages like c and c++ the function calls are linked at compile time with the linker (except with virtual functions which requires some runtime support). With languages that use a messaging system like objective-c and smalltalk, you cannot guarantee what functions will be run until runtime. The runtime determines if an object actually implements the function represented in the message. If it doesn't implement it, the class will usually either forward the message onto another object, or throw an exception. However, if the class does implement it, the runtime determines the address of the actual function, and calls it in the exact same manner as c (pushing the arguments and the return address onto the stack).\nOverall, a message is the same thing as calling a method directly, except the runtime finds the exact function to be called instead of it being linked at compile time.\nhttp://stackoverflow.com/questions/2068158/why-does-cocoa-use-delegates-rather-than-inheritance\nWith delegates, you can have one object be the delegate of many other objects. For example, you can have your MyController instance be the delegate of an NSTableView, an NSTextField, an NSWindow, and any other objects that compose your interface. This gives a compact place to put all of your user interface code related to one section of your UI.\nIf you'd done that with subclassing, you'd have to create one subclass every object you wanted callbacks from.\nNot only does delegation in C++ and Java mean writing more code, it is also not as performant as class inheritance. Implicit delegation by inheritance needs constant time, explicit delegation is linear. http://stackoverflow.com/questions/1209943/java-equivalent-of-cocoa-delegates-objective-c-informal-protocols?rq=1\n\nIn Python (and of course Objective-C), delegation can be achieved with as little as one extra method to delegate to one or more classes. Altering the number of parameters of a delegated method often requires a change to only one module.\n\n
http://stackoverflow.com/questions/5451926/is-message-passing-in-small-talk-and-objectivec-same-as-calling-method-with-valuOnce the actual function call is made, there is no difference. The difference between message passing and calling a method is in the linking. For languages like c and c++ the function calls are linked at compile time with the linker (except with virtual functions which requires some runtime support). With languages that use a messaging system like objective-c and smalltalk, you cannot guarantee what functions will be run until runtime. The runtime determines if an object actually implements the function represented in the message. If it doesn't implement it, the class will usually either forward the message onto another object, or throw an exception. However, if the class does implement it, the runtime determines the address of the actual function, and calls it in the exact same manner as c (pushing the arguments and the return address onto the stack).\nOverall, a message is the same thing as calling a method directly, except the runtime finds the exact function to be called instead of it being linked at compile time.\nhttp://stackoverflow.com/questions/2068158/why-does-cocoa-use-delegates-rather-than-inheritance\nWith delegates, you can have one object be the delegate of many other objects. For example, you can have your MyController instance be the delegate of an NSTableView, an NSTextField, an NSWindow, and any other objects that compose your interface. This gives a compact place to put all of your user interface code related to one section of your UI.\nIf you'd done that with subclassing, you'd have to create one subclass every object you wanted callbacks from.\nNot only does delegation in C++ and Java mean writing more code, it is also not as performant as class inheritance. Implicit delegation by inheritance needs constant time, explicit delegation is linear. http://stackoverflow.com/questions/1209943/java-equivalent-of-cocoa-delegates-objective-c-informal-protocols?rq=1\n\nIn Python (and of course Objective-C), delegation can be achieved with as little as one extra method to delegate to one or more classes. Altering the number of parameters of a delegated method often requires a change to only one module.\n\n
http://stackoverflow.com/questions/5451926/is-message-passing-in-small-talk-and-objectivec-same-as-calling-method-with-valuOnce the actual function call is made, there is no difference. The difference between message passing and calling a method is in the linking. For languages like c and c++ the function calls are linked at compile time with the linker (except with virtual functions which requires some runtime support). With languages that use a messaging system like objective-c and smalltalk, you cannot guarantee what functions will be run until runtime. The runtime determines if an object actually implements the function represented in the message. If it doesn't implement it, the class will usually either forward the message onto another object, or throw an exception. However, if the class does implement it, the runtime determines the address of the actual function, and calls it in the exact same manner as c (pushing the arguments and the return address onto the stack).\nOverall, a message is the same thing as calling a method directly, except the runtime finds the exact function to be called instead of it being linked at compile time.\nhttp://stackoverflow.com/questions/2068158/why-does-cocoa-use-delegates-rather-than-inheritance\nWith delegates, you can have one object be the delegate of many other objects. For example, you can have your MyController instance be the delegate of an NSTableView, an NSTextField, an NSWindow, and any other objects that compose your interface. This gives a compact place to put all of your user interface code related to one section of your UI.\nIf you'd done that with subclassing, you'd have to create one subclass every object you wanted callbacks from.\nNot only does delegation in C++ and Java mean writing more code, it is also not as performant as class inheritance. Implicit delegation by inheritance needs constant time, explicit delegation is linear. http://stackoverflow.com/questions/1209943/java-equivalent-of-cocoa-delegates-objective-c-informal-protocols?rq=1\n\nIn Python (and of course Objective-C), delegation can be achieved with as little as one extra method to delegate to one or more classes. Altering the number of parameters of a delegated method often requires a change to only one module.\n\n
http://stackoverflow.com/questions/5451926/is-message-passing-in-small-talk-and-objectivec-same-as-calling-method-with-valuOnce the actual function call is made, there is no difference. The difference between message passing and calling a method is in the linking. For languages like c and c++ the function calls are linked at compile time with the linker (except with virtual functions which requires some runtime support). With languages that use a messaging system like objective-c and smalltalk, you cannot guarantee what functions will be run until runtime. The runtime determines if an object actually implements the function represented in the message. If it doesn't implement it, the class will usually either forward the message onto another object, or throw an exception. However, if the class does implement it, the runtime determines the address of the actual function, and calls it in the exact same manner as c (pushing the arguments and the return address onto the stack).\nOverall, a message is the same thing as calling a method directly, except the runtime finds the exact function to be called instead of it being linked at compile time.\nhttp://stackoverflow.com/questions/2068158/why-does-cocoa-use-delegates-rather-than-inheritance\nWith delegates, you can have one object be the delegate of many other objects. For example, you can have your MyController instance be the delegate of an NSTableView, an NSTextField, an NSWindow, and any other objects that compose your interface. This gives a compact place to put all of your user interface code related to one section of your UI.\nIf you'd done that with subclassing, you'd have to create one subclass every object you wanted callbacks from.\nNot only does delegation in C++ and Java mean writing more code, it is also not as performant as class inheritance. Implicit delegation by inheritance needs constant time, explicit delegation is linear. http://stackoverflow.com/questions/1209943/java-equivalent-of-cocoa-delegates-objective-c-informal-protocols?rq=1\n\nIn Python (and of course Objective-C), delegation can be achieved with as little as one extra method to delegate to one or more classes. Altering the number of parameters of a delegated method often requires a change to only one module.\n\n
Don Han.\n\n
A protocol is essentially a group of functions/methods.\n\nA class that extends itself with the protocol promises to implement the methods in the protocol (optional or required).\n
Pre-written protocol called &#x201C;CLLocationManagerDelegate&#x201D; that we can use in our custom code.\n
How do we use it? Our UIViewController extends itself with all the Core Location functionalities pre-written in CLLocationManagerDelegate!\n
In our corresponding implementation file, we can use the methods declared in the CLLocationManagerDelegate!\n
Open Xcode and show everything else\n
\n
(As seen earlier)\n
This makes a lot of sense because we are essentially reusing a lot of established code already given to us by Apple&#x2019;s Cocoa Touch framework in various blablaDelegate.h files.\n
\n
\n
A parting message. What? Did I just contradict myself again?\n
Not really... &#x201C;Be water, my friend&#x201D;\n