Re: Objective-C Question [long]
Re: Objective-C Question [long]
- Subject: Re: Objective-C Question [long]
- From: publiclook <email@hidden>
- Date: Fri, 19 Sep 2003 11:27:17 -0400
On Thursday, September 18, 2003, at 04:34 PM, Jeff Galyan wrote:
I know this list is targeted to Cocoa framework questions rather than
Objective-C "newbie" type questions, so please forgive the somewhat
off-topic post.
Here's what I'm trying to find out:
I've been working with Cocoa and ObjC for some time, and I have yet to
find
a really compelling reason to abandon C++. Now, before the
semi-religious
flames erupt, please finish reading and give some thought to what I'm
asking.
Apple's own documentation answers the question, why Objective-C:
http://developer.apple.com/documentation/Cocoa/Conceptual/ObjectiveC/
2objc_oop/index.html
My own take:
1) Objective-C is much simpler than C++.
I particularly agree with the following quote:
"Moreover, Objective-C is a simple language. Its syntax is small,
unambiguous, and easy to learn. Object-oriented programming, with its
self-conscious terminology and emphasis on abstract design, often
presents a steep learning curve to new recruits. A well-organized
language like Objective-C can make becoming a proficient
object-oriented programmer that much less difficult. The size of this
book is a testament to the simplicity of Objective-C. Its not a big
book."
One way to explain the benefits of Objective-C compared to C++ is to
emphasize the many problems with C++. IMHO C++ is a gargantuan
language with so many subtleties, incompatibilities, internal
inconsistencies, potential hidden performance problems that is is an
undesirable choice for many applications. Does a a single ANSI/IOS
compliant compiler exist in the world yet ? When was the standard
dated " (1999?) Don't get me wrong, I am an expert C++ programmer and
I use it every day. Great software can be written with C++ just like
with any other languages. You can also drive nails with a wrench.
2) Objective-C is better suited to producing reusable libraries than
C++.
2a) Objective-C suffers from a much less severe Fragile Base Class
Problem than C++
First consider the Fragile Base Class Problem with C++ described well
at the following:
http://2f.ru/holy-wars/fbc.html
Objective-C does suffer from the Fragile Base Class problem to the
extent that adding instance variables to a class requires that all
subclasses be recompiled. However, adding and removing methods to a
base class does not require that derived classes are recompiled.
2b) An advantage of Objective-C categories relating to reusable
libraries:
http://www.omnigroup.com/mailman/archive/macosx-dev/2000-February/
000251.html
2c) Objective-C has no need for COM/DCOM in order to decouple a library
user from the library
http://groups.google.com/groups?q=Objective-
C+DCOM+Buck+IDL&hl=en&lr=&ie=UTF-
8&selm=5Ble5.1147$email@hidden&rnum=1
3) Objective-C is better suited to GUI programming.
3a) Why C++ is not very fit for GUI programming:
http://okmij.org/ftp/c++-digest/CPP-GUI-mismatch.html
Contrast simple implementations of standard patterns in C++ and
Objective-C. Many patterns require no code in Objective-C.
http://www.amazon.com/exec/obidos/tg/detail/-/0201633612/102-6711920-
1905730?v=glance
3b) The patterns used to implement libraries are very important. In
particular, the following C++ design patterns require little or no code
in Objective-C (In spite of or because of the fact that Objective-C is
a much simpler language)
Abstract Factory: This is implicit in Objective-C Class Objects.
Objective-C Class methods have historically been called "Factory"
methods.
Factory Method: Objective-C Class methods have historically been called
"Factory" methods.
Bridge: This capability is provided by Objective-C built in message
passing
Chain of Responsibility: Can be implemented simply in Objective-C
without also needing the Command pattern or an artificial messaging
system using tables or switch statements tacked on top of the language.
Command Pattern: Objective-C messages provide all of the benefits of
this pattern without writing any code.
Mediator: Objective-C's anonymous type, id, and the fact that any
message can be sent to any receiver make this pattern unnecessary.
Memento: This pattern is much simpler and does not need the Command
pattern or others in its Objective-C implementation.
Observer: See NSNotificationCenter. This pattern also avoids the need
for the Command pattern when used with Objective-C. The Objective-C
implementation is much simpler than the C++ implementation.
I would add the the "Delegate" pattern used with Objective-C in the
Cocoa Frameworks and others is an example of a powerful and simple
pattern that is enabled by Objective-C and very difficult to implement
in C++.
http://www.stepwise.com/Articles/Technical/2000-03-03.01.html
In summary:
The web is full of criticism of various C++ features such as templates,
operator overloading, name mangling, linkage constraints, fragile base
classes, incredible complexity, etc. Due to its simplicity and
adherence to a small number of core abstractions, Objective-C is not
prone to these problems.
Using the hammer analogy introduced in first post on this subject:
Objective-C is a hammer that is already on your tool belt. It can be
used with any kind of nail; It has no constraints on the type of nail
you use. It requires little training and provides a lot of power.
C++ is a collection of swiss army knifes inside a box that is locked
with a combination lock and guarded by a man named Static Binding. To
use C++ , you must first know the combination for the lock. The
combination has historically been changed every few years as new Swiss
army knives that provide tools called templates, exceptions, name
spaces, pure virtual base classes, etc. have been added. Of course,
the older versions of the knives are still in the box. Once the lock
is open, you must select one of the available Swiss army knives. Some
training about how to select a knife is advisable. Then before using
the selected Swiss army knife, you must get permission from the guard
who disallows the use of certain tools with certain nails. You can't
use Knife A with a galvanized nail, but the only tool you are allowed
to use with finishing nails is in Knife A. Therefore you are not
allowed to drive galvanized finishing nails. When you complain, the
guard criticizes you for not anticipating this constraint in your
design that foolishly did not conform to the limitations of your tools.
When you finally get past the guard, you realize the the Swiss army
knife is not very good at driving nails, because even though it
contains many useful (if seldom applied) capabilities, being a hammer
is not one of them. To be fair to C++, sometimes the bottle opener
component of the Swiss army knife is very handy, and although you can
open a bottle with a hammer, it has a tendency to be messy. For these
situations, the Swiss army knife may be preferred even if the Hammer is
generally more useful, simpler, and accessible. A lot depends on how
many nails you need to drive versus how many bottles you need to open.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.