home *** CD-ROM | disk | FTP | other *** search
- Path: senator-bedfellow.mit.edu!bloom-beacon.mit.edu!spool.mu.edu!howland.reston.ans.net!europa.eng.gtefsd.com!uunet!mcsun!sun4nl!tuegate.tue.nl!krait.es.ele.tue.nl!tiggr
- From: tiggr@es.ele.tue.nl (Tiggr)
- Newsgroups: comp.lang.objective-c,comp.answers,news.answers
- Subject: comp.lang.objective-c FAQ, part 1/3: Answers
- Supersedes: <answers_743346495@es.ele.tue.nl>
- Followup-To: comp.lang.objective-c
- Date: 17 Aug 1993 10:09:53 GMT
- Organization: Eindhoven University of Technology, the Netherlands
- Lines: 528
- Approved: news-answers-request@mit.edu
- Expires: 26 Sep 1993 10:09:52 GMT
- Message-ID: <answers_745582192@es.ele.tue.nl>
- Reply-To: tiggr@es.ele.tue.nl (Tiggr)
- NNTP-Posting-Host: krait.es.ele.tue.nl
- Summary: This first part of the comp.lang.objective-c FAQ postings
- tries to answer all your Objective-C questions.
- Originator: tiggr@krait.es.ele.tue.nl
- Xref: senator-bedfellow.mit.edu comp.lang.objective-c:1503 comp.answers:1638 news.answers:11484
-
- Archive-name: Objective-C/answers
- Version: $Id: answers,v 1.6 1993/08/06 12:50:51 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:
- @class
- @interface
- @implementation
- @public
- @selector
- @protocol
- @end
- Constructs:
- [aList add: anObject]; // send a message to an instance
- Types:
- id // 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 do 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 doesn'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 was measured
- using the Self/Smalltalk benchmark suite available by FTP from
- `self.stanford.edu:pub/Self-2.0.1'.)
-
- * 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?
-
- 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 and GNU CC 2.4, you can:
-
- @class Foo;
-
- declares the class Foo. [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 available in NeXTSTEP 3.0 and GCC 2.4.
-
- 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 and GCC 2.4 support protocols and forward declarations of
- classes. [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
-
- 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 Object Oriented Programming and the Objective C Language.
- Addison-Wesley Publishing Company, Reading, Massachusetts, 1993.
- ISBN 0-201-63251-9.
-
- Abstract: This book describes the Objective-C language as it
- is implemented for NeXTSTEP. While clearly targeted
- at NeXTSTEP, it is a good first-read to get to learn
- Objective-C.
-
- 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.
-
- `Porting NEXTSTEP Applications to Microsoft Windows',
- by Christopher Lozinski. NEXTWORLD EXPO Conference Proceedings,
- San Francisco, CA, May 25-27, 1993. Updated version of the article
- available from the author. Contact lozinski@cup.portal.com
-
- Abstract: This article describes how to develop Objective-C
- applications for both Microsoft Windows and
- NEXTSTEP.
-
- 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:
-
- Apple Macintosh (running Mac Programmers Workshop)
- DEC Stations (ULTRIX)
- Data General AViiON (DG/UX)
- HP9000/300,400,700,800 (HP-UX)
- IBM RISC System/6000 (AIX)
- MIPS
- NeXT
- PC-AT (MS-DOS)
- PS/2 (AIX or OS/2)
- SCO UNIX SYS V
- Sun 3, 4, SPARCstations (SunOS)
- VAX (VMS)
-
- Class libraries are available for a subset of the above.
- [Which?]
-
- The Stepstone Corporation
- (203) 426-1875 - (800) BUY-OBJEct voice / (203) 270-0106 fax
- 75 Glen Road
- Sandy Hook, CT 06482
-
- Q What kind of Objective-C support is provided by NeXT?
-
- The Objective-C compiler and libraries come bundled with the
- NEXTSTEP Developer CD. The compiler essentially is GNU CC. For
- information on the Kits which are part of NEXTSTEP, see the
- ClassWare Listing (part 2 of this FAQ).
-
- Products are:
-
- NeXTSTEP 3.0
- NEXTSTEP 3.1 for NeXT Computers
-
- NEXTSTEP 3.1 for Intel Processors
- Released on May 25 1993.
- User $ 795
- Developer $1895
- Educational (U+D) $ 295
- Evaluation Kit
- (U+D, no docs/upgrade) $ 295
-
- ObjectWare Catalogue of available classes, both commercial and
- freely available.
-
- NeXT, Inc.
- [address]
-
- Q What kind of Objective-C support is provided by GNU?
-
- A The current distribution of GNU CC (version 2.4.5) includes an
- Objective-C compiler and runtime library. The latter includes the
- `Object' class. Some people are working on the GNU libobjc.
-
- Free Software Foundation
- 675 Massachusetts Avenue
- Cambridge, MA 02139
- +1-617-876-3296
-
- General questions about the GNU Project can be asked to
- gnu@prep.ai.mit.edu.
-
- GNU CC comes with an Objective-C compiler and runtime
- library which includes the Object class.
-
- 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
-
- Q. What kind of Objective-C support is provided by BPG.
-
- BPG provides the Borland Extensions to Objective-C which allows the
- Objective-C translator to be used with the Borland Compiler, and makes
- it easy to develop Objective-C application for Microsoft Windows.
-
- BPG provides the Smalltalk Interface to Objective-C which makes
- Objective-C objects look like Smalltalk Objects. It can be used to
- build Graphical User Interface on portable Objective-C objects, or to
- sell Objective-C libraries to Smalltalk developers.
-
- BPG provides the Objective-C Message Bus which sends Objective-C messages
- across heterogeneous computer platforms.
-
- BPG has a library of objects for modelling Objective-C programs. A browser
- application has been built on this library. Other potential applications
- include adding class variables to Objective-C, adding runtime information
- about instance variables, and method argument types, generating object
- versions, and eventually building a browser/translator.
-
- Christopher Lozinski
- BPG
- 35032 Maidstone Court
- Newark, CA 94560
- Tel: (510) 795-6086
- fax: (510) 795-8077
- email: lozinski@cup.portal.com
-
- 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
- ccrma-ftp.stanford.edu 36.49.0.93 [MusicKit]
-
- [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.
-
- 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,
- Christopher Lozinski, Mike Mahoney, Paul Sanchez, Lee Sailer, Bill Shirley,
- 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
-