Thread View: comp.lang.objective-c
1 messages
1 total messages
Started by Tiggr
Thu, 17 Jun 1993 08:23
comp.lang.objective-c FAQ, part 1/3: Answers
Author: Tiggr
Date: Thu, 17 Jun 1993 08:23
Date: Thu, 17 Jun 1993 08:23
479 lines
20028 bytes
20028 bytes
Archive-name: Objective-C/answers
Version: $Id: answers,v 1.4 1993/06/17 08:08:55 tiggr Exp $
Answers to
FREQUENTLY ASKED QUESTIONS
concerning
Objective-C
This is the first in a series of three informational postings concerning
comp.lang.objective-c. This first part answers FAQs; the second part lists
available class libraries and the third part is a simple sample Objective-C
program.
Q What is Objective-C?
A Objective-C is an object oriented computer programming language. It is
a superset of ANSI C and provides classes and message passing similar to
Smalltalk.
Q What is the difference between Objective-C and C?
A Objective-C is a superset of ANSI C. It is an object oriented language
that has extensions similar to Smalltalk that are integrated into C
syntax without taking anything away.
It includes a few more keywords and constructs.
New Keywords:
@interface
@implementation
@public
@selector
@protocol
@end
Constructs:
[aList add: anObject]; <- sending a message to an instance
Types:
id - basically a generic pointer to an object
[This is nowhere near to what I would like it to be.]
Q What is the difference between Objective-C and C++?
A C++ follows the Simula 67 school of OO programming, where Objective-C
follows the Smalltalk school. In C++ the static type of an object
determine whether you can send it a message, in Objective-C the dynamic
type determine it. The Simula 67 school is safer, in that more errors
are detected at compile time. The Smalltalk school is more flexible, as
some valid programs will execute correctly in Smalltalk, where they
would be rejected by Simula 67.
Stepstone's Objective-C allows you to chose between the dynamic and
static binding, GNU and NeXT does not. ANSI C++ allows you to use
dynamic binding, but discourages you from doing so.
In many ways, the difference between C++ and Objective-C is more a
question of mindset than technical barriers. Are you willing to offer
some flexibility for some safety? Advocates for the Simula 67 school
claims that a well designed program don't need the extra flexibility (a
lie), while advocates for the Smalltalk school claims that the errors
are no problem in practice (another lie).
Pragmatic differences between Objective-C and C++ include:
C++ has operator overloading. Some consider this to be `syntactic
sugar', and it is, but it can be a quite handy bit of sugar.
C++ has multiple inheritance. There are several ways to `get
around' this in Objective-C (see below).
The added syntax and semantics of C++ is huge, while Objective-C is
C plus just a small number of new features.
Q What exactly is it that makes Objective-C have `classes similar to
Smalltalk', and what are the resulting capabilities of Objective-C?
A Objective-C is as close to Smalltalk as a compiled language allows. The
following is a list of the features `taken' from Smalltalk:
* Objective-C is compiled---Smalltalk is only partially compiled. The
current Objective-C implementations are all *much* faster than any
Smalltalk. For example ParcPlace Smalltalk-80/4 is at least 3 times
slower than both the GNU and NeXT Objective-C's. (This is measured
using the Self/Smalltalk benchmark suite available from
`self.stanford.edu'.)
* You may add or delete methods and classes at runtime. (This is done
via dynamic loading of object code. This is currently supported by
both NeXT and Stepstone Compilers [?].)
* Much of the syntax, i.e. Smalltalk uses method names like
`a:method:name:', as does Objective-C. In Objective-C, the message
sending construct is enclosed in square brackets, like this:
`[anObject aMessage: arg]' whereas Smalltalk uses something like
`anObject aMessage: arg'.
* The basic class hierachy, that is, having class `Object' in the very
top, and letting most other classes inherit from it.
* Most method names in class object is the same. E.g. `respondsTo:'.
What is called `doesNotUnderstand:' in Smalltalk is called
`doesNotRecognize:' in Objective-C.
* Smalltalk normally uses `doesNotUnderstand:' to implement
forwarding, delegation, proxies etc. This is handled via special
methods `forward::' and a special class (On NeXT named NXProxy)
which must be used for such purposes.
* Objective-C has meta classes mostly like Smalltalk.
* Objective-C does not have class variables like Smalltalk, but pool
variables and globals are easily emulated via static variables.
Q What are the `nice features' of Objective-C?
The possibility to load class definitions and method definitions
(which extend a class) at run time.
Typing information is available at run time. [Prime example:
NeXTSTEP's `-[Application loadNibSection:owner:]'.]
Persistence [...].
Remote objects [...].
Delegation and target/action protocols [...].
Q What are some of the common problems of the language and how can I work
around them? (forward declarations of classes, class variables)
A There is no innate multiple inheritance (of course some see this as a
benefit).
To get around it you can create a compound class, i.e. a class with
instance variables that are ids of other objects. Instances can
specifically redirect messages to any combination of the objects
they are compounded of. (It isn't *that* much of a hassle and you
have direct control over the inheritance logistics.) [Of course,
this is not `getting around the problem of not having multiple
inheritance', but just modeling your world slightly different in
such a way that you don't need multiple inheritance.]
Protocols address the absence of multiple inheritance (MI) to some
extent: Technically, protocols are equivalent to MI for purely
"abstract" classes (see the answer on `Protocols' below).
[** how does Delegation fit in here? **] [Delegation is extending a
class' functionality in a way anticipated by the designer of that
class, without the need for subclassing. One can, of course, be the
delegate of several objects of different classes...]
There are no class variables.
You can get around this by defining a static variable in the .m
file, and defining access methods for it. This is actually a more
desirable way of designing a class hierarchy, because it allows
subclasses shouldn't access superclass storage (this would cause the
subclass to break if the superclass was reimplemented), and allows
the subclass to override the storage (if the classes access all
their own variables via methods).
[The question remains what the exact syntax of class variables
should be: Should a class object A be seen as an instance of its
meta-class MA, which has a super class MB being the meta-class of
A's super, B, and, as such, should A have seperate instances of
class variables defined for B? Or not?]
You can't forward-declare classes.
In NeXTSTEP 3.0, you can:
@class Foo;
declares the class Foo. GNU CC can't do this. [And Stepstone?]
Q What are Protocols?
A Protocols are an addition to Objective-C that allows you to organize
related methods into groups that form high-level behaviors. Protocols
are currently only available in NeXTSTEP 3.0.
Protocols address the MI issue. When you design an object with multiple
inheritance, you usually don't want *all* the features of both A and B,
you want feature set X from A and feature set Y from B. If those
features are methods, then encapsulating X and Y in protocols allows you
to say exactly what you want in your new object. Furthermore, if
someone changes objects A or B, that doesn't break your protocols or
your new object. This does not address the question of new instance
variables from A or B, only methods.
Protocols allow you to get type-checking features without sacrificing
dynamic binding. You can say "any object which implements the messages
in Protocol Foo is ok for this use", which is usually what you want -
you're constraining the functionality, not the implementation or the
inheritance.
Protocols give library builders a tool to identify sets of standard
protocols, independent of the class hierarchy. Protocols provide
language support for the reuse of design, whereas classes support the
reuse of code. Well designed protocols can help users of an application
framework when learning or designing new classes. Here is a simple
protocol definition for archiving objects:
@protocol Archiving
-read: (NXTypedStream *) stream;
-write: (NXTypedStream *) stream;
@end
Once defined, protocols can be referenced in a class interface as
follows:
/* MyClass inherits from Object and conforms to the
Archiving protocol. */
@interface MyClass: Object <Archiving>
@end
Unlike copying methods to/from other class interfaces, any incompatible
change made to the protocol will immediately be recognized by the
compiler (the next time the class is compiled). Protocols also provide
better type checking without compromising the flexibility of untyped,
dynamically bound objects.
MyClass *obj1 = [MyClass new];
// legal, obj2 conforms to the Archiving protocol.
id <Archiving> obj2 = obj1;
// illegal, obj1 does not conform to the TargetAction protocol.
id <TargetAction> obj3 = obj1;
[The `illegal' remark in the comment is a bit far-sought. The real use
of declaring an ID to conform to some protocol is that it can help the
compiler to resolve method name conficts:
@interface Foo: Object
-(int) type;
@end
@protocol Barf
-(const char *) type;
@end
-blah1: d
{
id t = [d someMethod];
do_something_with ([t type]);
}
-blah2: d
{
id <Barf> t = [d someMethod];
do_something_with ([t type]);
}
In this example, there are two kinds of the `-type' method. In the
method `-blah1:', the compiler doesn't know what to expect from `[t
type]', since it has seen both declarations of `-type'. In method
`-blah2:', it knows that `t' conforms to the `Barf' protocol and thus
that `t' implements the `-type' method returning a `const char *'.]
Q What is the difference between the NeXTSTEP, Stepstone and GNU CC
versions of Objective-C?
A NeXT extended Stepstones definition of the language to include new
constructs, such as protocols, which are touted to deal with some
aspects of multiple inheritance.
Stepstone supports static _binding_, whereas NeXTSTEP and GNU CC don't.
All implementations do support static _typing_.
Stepstone has a standard set of class libraries that work across all
supported machines. NeXTSTEP comes with its own set of libraries
(called `kits'). GNU libobjc.a currently only includes the `Object'
class.
The `Object' class of all implementations differ.
NeXTSTEP and GNU CC support Categories, Stepstone doesn't.
NeXT has a native language debugger, Stepstone and GNU don't. [This is
not really true, since NeXT's debugger is gdb, the GNU debugger, and
their extensions are available. I think I've seen them on the Fall 1992
Edu CD. Their extensions haven't appeared in the official FSF]
NeXTSTEP 3.0 supports Protocols and forward declarations of classes.
GNU CC doesn't. [And Stepstone?]
Q What written information concerning Objective-C is available?
A Books:
Object Oriented Programming: An Evolutionary Approach
Author: Brad J. Cox (, Andrew J. Novobilski second edition)
Publisher: Addison-Wesley
ISBN#: 0-201-10393-1 August, 1986
ISBN#: 0-201-54834-8 1991
two editions
Objective-C: Object Oriented Programming Techniques
Authors: Lewis J. Pinson, Richard S. Wiener
Publisher: Addison-Wesley, 1991
ISBN#: 0-201-50828-1
Abstract: Includes many examples, discusses both Stepstone's
and NeXT's versions of Objective-C, and the (minor)
differences between the two.
An Introduction to Object-Oriented Programming
Author: Timothy Budd
Publisher: Addison-Wesley
ISBN#: 0-201-54709-0
Abstract: An intro to the topic of OOP, as well as a comparison
of C++, Objective-C, Smalltalk, and Object Pascal
NeXTSTEP Programming Step ONE: Object-Oriented Applications
Authors: Simson L. Garfinkel, Michael K. Mahoney
Publisher: TELOS/Springer-Verlag, 1993 (800)SPR-INGE
Availablility: First printing (6000 copies) sold out in 3 months.
Abstract: It's updated to discuss NeXTSTEP 3.0 features
(Project Builder, new development environment)
but doesn't discuss 3DKit or DBKit
NeXTSTEP Developer Manuals
Publisher: Addison Wesley
[...]
Articles
`Why I need Objective-C', by Christopher Lozinski.
Journal of Object-Oriented Programming (JOOP) September 1991.
Abstract: This article discusses the differences between C++
and Objective-C in great detail and explains why
Objective-C is a better object oriented language.
`Concurrent Object-Oriented C (cooC)', by Rajiv Trehan et. al.
ACM SIGPLAN Notices, Vol. 28, No 2, February 1993.
Abstract: This article discusses cooC, a language based on the
premise that an object not only provides an
encapsulation boundary but should also form a
process boundary. cooC is a superset of
Objective-C.
GNU Documentation
The GNU progrects needs a free manual describing the Objective-C
language features. Because of its cause, GNU cannot include the
non-free books in the GNU system, but the system needs to come with
documentation.
Anyone who can write good documentation, please think about giving
it to the GNU project. Contact rms@gnu.ai.mit.edu.
Q What kind of Objective-C support is provided by Stepstone?
Compilers and runtime for:
IBM RISC System/6000 w/ AIX
Sun 3, 4, SPARCstations w/ SunOS
HP9000/300,400,700,800 w/ HP-UX
DEC Stations w/ ULTRIX
Data General AViiON w/ DG/UX
SCO UNIX SYS V
PS/2 w/ AIX or OS/2
PC-AT w/ MS-DOS
VAX w/ VMS
MIPS
NeXT
Macs with MPW (Mac Programmers Workshop)
Class libraries are available for a subset of the above.
[Which?]
Q What kind of Objective-C support is provided by NeXT?
Objective C compiler and libraries come bundled with the
extended OS release, which comes on CDROM. The compiler is
essentially GNU CC; the libraries include:
AppKit Excellent class library for creating
programs running the NeXTSTEP GUI.
DBKit DatabaseKit, providing OO access to databases
through adapters. Adapters for Sybase and Oracle
are included.
IXKit Indexing kit, a `how to store, index and access
large amounts of information' library.
3DKit Providing access to Pixar Renderman technology.
Q What kind of Objective-C support is provided by GNU?
A The current distribution of GNU CC (version 2.3.3) includes an
Objective-C compiler and runtime library. The latter includes the
`Object' class. A new, faster runtime is currently being developed by
Kresten Krab Thorup. Some people are working on the GNU libobjc.
[The 2.3.3 runtime contains one severe bug causing programs compiled
with it to complain about not being initialized and failing to run.
This is easily fixed.]
Q What are the newsgroups to read or mailinglists to subscribe to in order
to stay up-to-date on developments for GNU Objective-C?
A Read comp.lang.objective-c, which is bound to discuss current events.
There is also a mailinglist, gnu-objc@gnu.ai.mit.edu, discussing this
very topic. To subscribe to this list, send a mail with your request to
`gnu-objc-request@gnu.ai.mit.edu.'
Q Are there any FTP sites with Objective C code? Where?
A NeXTSTEP sites:
sonata.cc.purdue.edu 128.210.15.30
cs.orst.edu 128.193.32.1
ftp.stack.urc.tue.nl 131.155.2.71
[What about other sites?]
Q What class libraries are available for Objective C?
A See the related FAQ file objc-faq/classes.
Q So show me a program, a simple example.
A See the related FAQ file objc-faq/sample.
Q Who makes an Objective-C compiler, what does it cost, how do I order?
A There are 3 sources:
The Stepstone Corporation
(203) 426-1875 - (800) BUY-OBJEct voice / (203) 270-0106 fax
75 Glen Road
Sandy Hook, CT 06482
[Pricing?]
NeXT, Inc.
NeXTSTEP 3.0 - $295 [?] shipped Sept 92.
NeXTSTEP486 - $800/$2000 intended release 25 May 1993.
Free Software Foundation
For information on how to order GNU software on tape,
floppy, or cd-rom, check the file etc/DISTRIB in the GNU
Emacs distribution, or e-mail a request to:
gnu@prep.ai.mit.edu
GNU software is available from the following sites:
Asia: utsun.s.u-tokyo.ac.jp:/ftpsync/prep,
ftp.cs.titech.ac.jp, cair.kaist.ac.kr:/pub/gnu
Australia: archie.oz.au:/gnu
Europe: ftp.informatik.tu-muenchen.de,
src.doc.ic.ac.uk:/gnu, nic.funet.fi:/pub/gnu,
ugle.unit.no, isy.liu.se, nic.switch.ch:/mirror/gnu,
archive.eu.net, ftp.informatik.rwth-aachen.de:/pub/gnu,
ftp.stacken.kth.se, ftp.win.tue.nl, ftp.denet.dk,
ftp.eunet.ch, irisa.irisa.fr:/pub/gnu
United States: wuarchive.wustl.edu, ftp.cs.widener.edu,
uxc.cso.uiuc.edu, col.hp.com:/mirrors/gnu,
gatekeeper.dec.com:/pub/GNU, ftp.uu.net:/systems/gnu
The early version of this FAQ was compiled by Bill Shirley, with the aid of
many people. The current version is being maintained by Tiggr, aided by a
lot of people, including: Per Abrahamsen, Paul Burchard, Brad Cox, Mike
Mahoney, Paul Sanchez, Lee Sailer, Bill Shirly, Subrata Sircar, Ted
Slupesky, Richard Stallman and Kersten Krab Thorup,
Any text in between `[' and `]' is a comment. Comments indicate problems
with this FAQ, which should be solved. Send your suggestions, additions,
bug reports, comments and fixes to `tiggr@es.ele.tue.nl'.
--
--Tiggr
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads