A Definition of Dynamic Programming in the Cocoa World
When I talk about dynamic programming on iOS and Mac, I mean this:
-
An app can learn about its structure at runtime.
-
An app can do things based on what it knows about its structure.
-
An app can make changes to its structure.
The first is things like knowing what methods an instance implements, or getting a reference to a protocol, class, or method from a string. (As in NSSelectorFromString and so on.)
The second is things like being able to instantiate a class where the name wasn’t known at compile time, or to call a method or reference a property that wasn’t known at compile time. (As with performSelector:
, KVC, the responder chain, and xib and storyboard loading.)
The third is things like adding methods at runtime (a la Core Data) or adding classes — for instance, by loading compiled code from disk (plugins).
(Note — because people sometimes misread what I write — this definition is not advocacy for a particular style of programming, nor is it a judgment of Swift, which, I repeat, I love, and is my preferred language. It’s to help us know what we’re talking about when we talk about dynamic programming.)