Re: To C++ users trying to use Cocoa
Re: To C++ users trying to use Cocoa
- Subject: Re: To C++ users trying to use Cocoa
- From: Erik Buck <email@hidden>
- Date: Sat, 12 May 2007 19:16:32 -0400
Moments of sudden revelation or insight regarding Objective-C/Cocoa
relative to C++/<some framework> have been occurring at what seems to
be a steady rate since around 1989 when the technology that would
later be called Cocoa became widely available.
Interestingly (but off topic), there are similar regular epiphanies
regarding List and Smalltalk.
My own epiphany regarding Cocoa is (somewhat embarrassingly) archived
in google groups for anyone who is interested. Twelve years later, I
wrote the following obligatory car analogy to explain what it is that
makes Objective-C/Cocoa so compelling for some people and why others
will never like it:
Excerpted from <http://www.samspublishing.com/articles/article.asp?
p=29979&seqNum=5&rl=1>
There are two general types of applications: closed world and open
world. Objective-C's flexibility and power are generally
inappropriate for closed-world applications but much more suited for
open-world applications as described in the following sections.
Closed-World Applications
The engine compartment of an automobile is analogous to closed-world
applications. It is desirable to know in advance every component that
will be inside the engine compartment and how they will fit together.
Engines are carefully designed and their design is seldom modified
after they leave the factory. Any variation in the connections
between engine components is probably a manufacturing error.
Languages such as C++ and to a lesser extent Java provide language-
level features that are well-suited to solving closed-world problems.
The static strong typing used by C++ and Java enables the compiler to
verify that all components fit together as planned at the cost of
making variation, redesign, and modification of existing applications
more difficult. Some applications require the verifiability of static
strong typing and can overcome the reduction in flexibility. Some
programmers are just more comfortable solving closed-world style
problems and might never be satisfied with Cocoa because it is
designed to solve open-world problems.
Open-World Applications
The passenger compartment of an automobile is analogous to open-world
applications. Any constraints on the type or number of people and
things that can be placed in the passenger compartment detract from
the utility of the automobile. Some constraints are inevitable, but
the designer of a passenger compartment must strive for maximum
flexibility. The price of that flexibility is that the designer
cannot anticipate everything that might be put in the passenger
compartment. The designer must work with incomplete information.
Objective-C provides language-level support for solving open-world
problems. Objective-C objects can operate with anonymous objects in
different applications. It is possible to send messages to objects
even though the receiver might not understand the message. It is
possible to add behaviors to existing compiled objects without
recompiling them. The flexibility provided by Objective-C aids the
development and life-cycle modification of most desktop applications,
but the cost is that the compiler cannot always verify that the
components fit together. In some cases, errors that might have been
caught by a compiler with a different language cannot be caught until
an Objective-C application is running.
Most graphical user interfaces are examples of open-world
applications. Restrictions on the type and number of graphical
components available reduce the utility of user interfaces. Sometimes
it is necessary to create new user interface components that were not
anticipated by the original designers and still be able to integrate
the new components with the old components. Plug-ins and context
menus are other examples of open-world applications.
It is certainly possible to create open-world applications with
static strongly typed languages, but it is more difficult. It is also
possible to use strong static typing with Objective-C and gain many
of the benefits at the cost of flexibility. Cocoa and Objective-C
emphasize flexibility at the expense of compile time verifiability.
Much of the increased programmer productivity attributed to using
Cocoa results from Objective-C's flexibility.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden