Talk:Objective-C/Archive 1

Page contents not supported in other languages.
From Wikipedia, the free encyclopedia
Archive 1

Domain

objective-c.org's ownership is still lost, at least October 2002 through March 2003. If it becomes relinked, please fix it. Otherwise be warned it is one of those casino ads+list of searches pages. -User:Geoffrey —The preceding unsigned comment was added by Minesweeper (talkcontribs) 22:24, 18 October 2003 (UTC)

Title of article

The programming languages master list(s) seem to be switching the primary page names to <language> programming language, meaning "Objective-C" should probably be changed to "Objective-C programming language", which currently is redirected. Brent Gulanowski 19:40, 24 Oct 2003 (UTC)

Read Wikipedia:Naming conventions (languages) and the talk page carefully to see why this doesn't have " programming language" added. There are some who favor adding it always, but they're probably Pascal programmers. :-) :-) Stan 21:03, 24 Oct 2003 (UTC)
Agreed. There is no ambiguity here. —Preceding unsigned comment added by 90.5.7.87 (talk) 01:04, 1 September 2008 (UTC)

Validity of disadvantages?

The listed disadvantages are somewhat questionable: Garbage collection, Operator overloading, Multiple inheritance, and C primitive types not first-class objects

Given the purpose and use of Objective-C, these features are certainly of questionable benefit. In addition, comparison to C#, Java, or Python is particularly unfair, as the languages are intended for considerably different purposes. —The preceding unsigned comment was added by 64.81.64.115 (talkcontribs) 05:36, 12 November 2004 (UTC)

I may agree with GC, OO, multiple inheritance, but not having some sort of treatment of C primitive types as first-class objects can be downright annoying at times, though I can understand completely why it's not done so. Dysprosia 08:56, 12 Nov 2004 (UTC)

Clarifications

Among other clarifications, I deleted the following section, because most of it addresses attributes of the Mach-O runtime architecture/file format, not the Objective-C language itself. Other than delegation and remote invocation, none of the following is or was specific to Objective-C. NeXT machines did have some of the first widely available shared library support, and did support multiple architectures in the Mach-O file format (circa NeXTstep/OpenStep 4.0), but none of these runtime features were intimately bound with the Objective-C language.

Other features

ObjC in fact included a laundry-list of features that are still being added to other languages, or simply don't exist at all. These led from Cox's (and later, NeXT's) realization that there is considerably more to programming than the language. The system has to be usable and flexible as a whole in order to work in a real-world setting.

  • Delegating methods to other objects at run-time is trivial. Simply add a category that changes the "second chance" method to forward the invocation to the delegate. Presto!
  • Remote invocation is trivial. Simply add a category that changes the "second chance" method to serialize the invocation and forward it off.
  • Swizzling allows for classes to change at runtime. Typically used for debugging where freed objects are swizzled into Zombies, whose only purpose is to report an error when someone calls them. Swizzling was also used in EOF to create database faults. Swizzling is used today by Apple's Foundation Framework to implement Key-Value Observing.
  • All libraries are dynamically linked. This meant that large Objective-C programs were in fact quite small, because the library was already on the machine. Common today perhaps, but this is from the early 1980s when dynamic linking was fairly rare.
  • Libraries can be supplied in multiple versions in a single file. Applications can choose to use a specific version (4.3.2), the latest version (which happens to be 5.2.1), or even the latest of a particular major release (anything from 4.x). Versioning problems like this continue to haunt other systems to this day, including Java and component object model.
  • Code can be provided in multiple object formats for different platforms, in a single library. This avoids the need for a virtual machine entirely. Typical multi-platform Objective-C programs are smaller than most single-platform programs on other systems.
  • Archiving. An object can be archived into a stream, such as a file, and can be read and restored on demand.

—The preceding unsigned comment was added by 64.81.33.177 (talkcontribs) 07:14, 14 November 2004 (UTC)

I had reverted this (for an accidental reason), but this material still is relevant, as Objective-C is not just the language, but the runtime as well. We can probably lose the multiple object format comment, however. You admitted yourself that delegation and remote invocation are part of the language, so these were replaced, as with swizzling and archiving, which are also part of the language. Dysprosia 07:25, 14 Nov 2004 (UTC)

Getting better all the time

If there was ever proof that the wiki "works", this article is it. I wrote the first draft over a period of a few days and now I see it has been greatly expanded and much more readable.

Some comments:

1) the reason I mentioned the library format in this article is that I felt that it went hand-in-hand with the reusability issue. Without a good library system reusability is often reduced to cut-n-paste of source code. I agree it was not at all clear that there was a distinction, however, and perhaps the article should include a section on these issues under a "ObjC in Next" type heading?

2) Multiple inheritance is one of the features that I find sorely missing from ObjC. Whenever you actually dig into the implementation details, you find that the REAL reason a language doesn't include it is that it makes the classloader more difficult to write (sometimes lots). However this simply moves the problems off of them and onto us.

3) I think GNU's implementation of GC deserves some expansion, as I believe they did it cleanly and in a very usable manner. IMHO, Apple would do well to simply copy it outright.

Any comments here? Should I just dive in?

Maury 13:22, 1 Dec 2004 (UTC)

briefly, in response to (2): In 18 years of solid ObjC programming, I have only once thought that I needed multiple inheritance. It turned out that there were two reasons why this was not true. First of all, NSArray solved all of the problems with its -makeObjectsPerform: method. Second of all, and perhaps more importantly, the schema was incredibly poorly designed - i.e we never would have had the problem with a sane design. At the time, we had Java as an option, which does not allow multiple inheritance, either. For the better part of a decade, I have thus been convinced that multiple inheritance is neither necessary nor even difficult to avoid. But you have to know ObjC well and not think like a C++ designer. BrianWilloughby (talk) 14:02, 22 June 2010 (UTC)

In response to Maury

Being a newbie to Objective-C, but a big fan, I would offer the following opinion

perhaps the article should include a section on these issues under a "ObjC in Next" type heading?

These are perhaps better left to the articles on Cocoa (software), or NeXT, under the history section. The NS* object framework is a vendor-supplied library, and not like a "standard library" in the C sense. Then again, I wonder how many ObjC newbies like myself would agree with the statement "delegation is trivial" if NSObject didn't come shrinkwrapped with the -delegate and -setDelegate: methods.

True but NeXT added features to the original language spec.

Apart from this, I think there are two main points about reusability, unrelated to what library you use...

  • You can use C sources in the middle of your Objective-C project without porting, something you absolutely cannot do with C++.
  • You can add methods to a class without subclassing it or having the implementation source code available to you. This feature, as I understand it, is unique to ObjC and its predecessor Smalltalk.
Multiple inheritance is one of the features that I find sorely missing from ObjC.
It's one of the main things that sets Objective-C above confused languages like C++. At any rate: that's an 'opinion' and even your comment has no place in a discussion of this article.

I don't disagree with this statement, but I don't think it's encyclopedic. It would be cool for someone to give a good pro/con discussion of multiple inheiritance over protocols/categories/delegation; did Smalltalk not have multiple inheiritance? It seems that protocols and delegation give you a way of avoiding it, keeping classes simple but instances complicated.

AFAIK Smalltalk did not have multiple inheritance. At any rate Objective-C studiously avoids it.

--Iluvcapra 01:20, 4 Dec 2004 (UTC)

3) I think GNU's implementation of GC deserves some expansion, as I believe they did it cleanly and in a very usable manner. IMHO, Apple would do well to simply copy it outright.
GNU did not implement GC with GCC. It uses the boehm-gc garbage collector AFAICR
Yes, but they added it. It's a GNU extension. —The preceding unsigned comment was added by Maury Markowitz (talkcontribs) 19:24, 5 December 2004 (UTC)
Re multiple inheritance, the way mixins are used in multiple-inheritance languages are precisely what categories are for, so I would agree with Iluvcapra's statement about protocols and other functionality giving you a way of avoiding it. Categories are so much more useful and obvious anyway ;)
Anyway, those are my 2c. Dysprosia 04:32, 4 Dec 2004 (UTC)

"Strong Typing"

The article mentions "strong typing" all the time where they in fact mean "static typing". All in favor of replacing? Wouter Lievens 12:44, 11 Mar 2005 (UTC)

Yes, of course. Dysprosia 00:02, 12 Mar 2005 (UTC)
Allright I'll do it Wouter Lievens 08:55, 22 Mar 2005 (UTC)

Misunderstanding in Language Analysis section

All Objective-C implementations have always had a runtime that did the message passing. The difference between the original Stepstone product (and Stes's POC) and Apple's GCC extensions is that Stepstone implemented Objective-C as a preprocessor whilst NeXT (and later Apple) made a true Objective-C compiler that didn't have C code as its output. -The preceding unsigned comment was added by 67.161.42.199 (talkcontribs) 11:54, 8 April 2005 (UTC)

In all methods, parameters are defined with a colon followed by the expected parameter type in parentheses and the parameter name. In some cases it is useful to add descriptive text before each parameter, and in some cases it is unnecessary. When working with large projects it is often very useful to have long, descriptive method names that make it easier to determine how each parameter is used.

-(void) setRange:(int)start :(int)end;

-(void) importDocumentWithName:(NSString *)name withSpecifiedPreferences:(Preferences *)prefs beforePage:(int)insertPage;

I'm assuming that the second line in the code above is an example where optional "descriptive text" is shown. I'm assuming that the two examples of descriptive text are "withSpecifiedPreferences", and "beforePage". Is there any syntax mistakes in this code segment? It would seem to me that the descriptive text are not in their proper sections, separated by the colons. This seems a little confussing and seems like it needs to be corrected or have a quick explaination inserted that it is indeed correct because... Richwalt (talk) 21:21, 12 March 2008 (UTC)

to answer your question, there are no syntax errors in the example. In fact, it uses the preferred white space. Keep in mind that, like most C languages, Objective-C allows a lot of valid options for white space. BrianWilloughby (talk) 14:00, 22 June 2010 (UTC)

Only One Syntax Change

Objective-C is a very "thin" layer on top of C. In fact it includes only one syntax change and about a dozen new keywords.

Am I the only one who thinks that's totally inaccurate? Looking at the code snippets, it seems clear that there are quite a few very large syntax changes. -- Dpark 07:42, 2 May 2005 (UTC)

That's possibly true, but there really isn't all that much different from C. What's markedly different is the comparatively different way things are written in Objective-C than in straight C. The only syntax changes are the square brackets for method calls and the notation for method calls, the rest is merely keyword changes, eg "@interface", etc. I'll change that to two syntax changes. Dysprosia 09:11, 2 May 2005 (UTC)
Well, adding new keywords necessarily requires syntax changes. The entire concept of objects is absent from C. And this kind of code is completely different from C style code:
- (int)changeColorWithRed:(int) r green: (int) g blue: (int) b
...
[myColor changeColorWithRed:5 green:5 blue:5];
None of the code snippets in this article really look like C to me at all. I don't want to just remove the info, but I'd like to revise it so it makes sense to people who are familiar with C but not Objective-C. But without understanding what the "single" syntax change (or "two" syntax changes) is, I don't know how to fix it. -- Dpark 18:24, 2 May 2005 (UTC)
Those are the only two syntax changes I mentioned and changed. Other than the other keywords, it's all compatible with C. Have a look at the "Observer.m" file in the article. If you don't rely on OPENSTEP-style memory management, you use C-style memory management. The for loops, pointers, etc., it's all C.
None of the following lines (except the "else") or several others in the code are C syntax:
@implementation Observer
- (retval_t) forward: (SEL) sel : (arglist_t) args
  id <Notifiable> *ptr;
     if([element respondsTo:sel] )
        [element performv: sel : args];
     else
        [element error:"Unrecognized message sent via Observer"];
@end
Interpretting all of that requires significant syntax changes from C. I'm not saying that Objective-C isn't a strict superset of C. But it seems that it has a significant number of additions to the syntax. -- Dpark 03:46, 3 May 2005 (UTC)
I would point out that this sample is
@implementation Observer
New keyword line, defines a "namespace" (a class)
- (retval_t) forward: (SEL) sel : (arglist_t) args
Functionally, the same as
(retval_t) forward(SEL sel, arglist_t args)
namely, a function/method definition.
  id <Notifiable> *ptr;
Just another pointer declaration to some type.
     if([element respondsTo:sel] )
        [element performv: sel : args];
     else
        [element error:"Unrecognized message sent via Observer"];
Standard C syntax --
     if( boolean test )
        statement ;
     else
        statement ;
@end
ending keyword.
Maybe what's needed is the explicit mention that the two new syntaxes are:
1. Method declaration lines,
2. "[target operands]" is an rvalue expression.

--Keybounce 19:50, 16 May 2006 (UTC)

Don't forget that while C has no real concept of a dedicated object, this doesn't mean that there is a syntax change. A Objective-C object can be "casted down" to a struct, but it's not very common and isn't such a great idea in writing code. Dysprosia 03:15, 3 May 2005 (UTC)
I'm talking about the syntax used for declaring interfaces, declaring implementations, messaging, etc. It's all new syntax. -- Dpark 03:46, 3 May 2005 (UTC)

I've removed the line for now at least. If someone can explain what it was trying to convey, I'll try to rewrite it in a way that makes more sense, but this article is being cited elsewhere, and it's simply not correct. New language features require new syntax, and Objective-C has several language features not found in C. -- Dpark 03:58, 3 May 2005 (UTC)

Looking at the history, this:

Objective-C's syntax is based on Smalltalk, and is is different from that of C or C++

was suddenly changed to this:

Objective-C is a very "thin" layer on top of C. In fact it includes only one syntax change and about a dozen new keywords. The syntax change is for calling methods on objects, and is based on Smalltalk as opposed to C++.

That's a rather different message. I'm going to edit the section to say that Objective-C has a syntax borrowing from both C and Smalltalk. -- Dpark 04:13, 3 May 2005 (UTC)

Declaring interface/implementation is not really new syntax. It's merely using the new ways of writing methods and the new keywords in a certain block. That doesn't make it a new syntax altogether. Dysprosia 04:31, 3 May 2005 (UTC)
The syntax of a language defines what is legal. Interface/implementation declarations have a syntax. All language features have a syntax. -- Dpark 04:52, 3 May 2005 (UTC)
Ok, I think I see what you mean here. Dysprosia 05:04, 3 May 2005 (UTC)

Object to the use of this phrase (no pun intended, but hey... )

"Since Java was influenced by Objective-C, this is also the case in Java."

Even if there is evidence for this causal link, the sentence should be rewritten to one indicating that .. "The design of Objective-C contributed to the choice of single inheritance over multiple inheritence for Java."

i.e. contributed rather than caused. —The preceding unsigned comment was added by 203.109.157.73 (talkcontribs) 21:39, 29 June 2005 (UTC)

You can fix this yourself, you know. By the way, see the Java article's external links for a document for evidence, if you're interested. Dysprosia 30 June 2005 02:44 (UTC)

GCC and #import

I was trying to find some information on why GCC insists on complaining about #import; and as always, a Wikipedia article was one of the top links. (This one, obviously.) I think it would be good to add something on that in the article.

However, I'm not sure exactly what. Here's a snippet from the comp.lang.objective-c newsgroup FAQ:

3.4 Why am I lectured about using #import ?
The GNU Objective-C compiler emits a warning when you use #import because some people find using #import poor style. You can turn off the warning by using the -Wno-import option, you could modify the compiler source code and set the variable warn_import (in the file cccp.c) or you could convert your code to use pairs of #ifndef and #endif, as shown above, which makes your code work with all compilers.

But the GNUstep user FAQ says the following:

1.2.4 What are these import warnings?
Do you get this obnoxious warning whenever you compile an application, tool, or Objective-C program:
warning: using `#import' is not recommended
[...]
Up until gcc 3.4, the #import directive was not implemented correctly. As a result, the GCC compiler automatically emitted a warning whenever #import was used. As of gcc 3.4, this problem has been fixed, so presumably, this warning is no longer emitted when code is compiled. If you are using an early compiler, you can supress these warnings by adding -Wno-import to your include (cpp) flags.

And leaving semi-official sources, there's all sorts of explanations, mostly "political reasons". So, style, politics, bad implementation, or something else? Does anyone here know? -- magetoo 17:07, 3 December 2005 (UTC)

There is absolutely nothing wrong with using #import, as long as it works properly. The reason I recall that the compiler spat out before was that declaration that the header should be included once should be made in the header, not in the code, but using #ifndef guards has never been traditional Objective-C style. Dysprosia 02:46, 7 January 2006 (UTC)

Exception catching

I am not sure, but is there 'try ... except'-like construction in Objective-C? —The preceding unsigned comment was added by Pdemb (talkcontribs) 21:08, 6 January 2006 (UTC)

Yes, in the Apple extensions to Obj-C, but not in the GNU implementation. Dysprosia 02:46, 7 January 2006 (UTC)
In GNU since GCC 3.3. My book mentions only old Cocoa NS_ macros. --Pdemb 11:51, 8 January 2006 (UTC)
That doesn't mean you can use them. If you actually read the gcc manpage: "Currently, this option[-fobjc-exceptions] is only available in conjunction with the NeXT runtime on Mac OS X 10.3 and later." Dysprosia 12:17, 8 January 2006 (UTC)

Categories

The article implies that Objective-C created method categories and runtime loading of categories, while both of these ideas came from Smalltalk. It seems that the idea in Smalltalk was to use this for documentation, not extension, as classes could also be categorized. However I don't know how method categories were actually used. —The preceding unsigned comment was added by 69.12.192.122 (talkcontribs) 15:36, 10 April 2006 (UTC)


Isn't there a clear link between these categories and the notion of a Mixin? —Preceding unsigned comment added by 83.241.184.66 (talk) 13:57, 5 November 2007 (UTC)

Class Clusters

Completely missing from this article is any discussion of class clusters.

Class clusters is wrapping a large number of classes into a single public class. As an example, all the various number types -- short, int, long, float, double, etc -- have wrapper class -- NSShort, NSLong, etc --, and a grandparent wrapper NSNumber.

When you create an NSNumber, you automatically get an appropriate subclass.

This setup is extendable -- you could, for example, add a complex number type underneath NSNumber.

Class clusters requires categories, at least if they are extendable -- for the complex, for example, you need to be able to add something to NSNumber that can return your new complex class.

I don't know if Java 1.5 added anything to support this, but this type of construct was impossible in Java 1.4 and earlier, because of that need for categories.

As for basic types "Not full class citizens", years ago there was a preprocessor for statements like:

result @= a @* b @+ c;

that would turn it into math calls on those variables (assuming they were NSNumbers, or another class with similar methods.) This basically meant that an NSNumber wrapper was a full citizen.

Another example of a class cluster might be a wrapper on a read-only file -- depending on the file, it might be implemented as a memory mapped file, or a standard file that was seek'd around in. --Keybounce 19:41, 16 May 2006 (UTC)

The 'Messages' section is a good place to mention class clusters. It is because of the dynamicism mentioned in this section that class clusters work. —The preceding unsigned comment was added by Harveyswik (talkcontribs) 08:24, 16 October 2006 (UTC)

Biased and unsupported statement

I have just removed the following biased and unsupported statement from the article:

For these reasons, C++ has been popular for big, in-house, corporate projects, written by teams of average-proficiency developers, who must be treated as interchangeable resources. ObjC is more popular as a language for development of commercial or independent applications, by one or a few, high-proficiency developers.

This strikes me as POV-pushing at its worst. Unless someone can produce citable references that C++ is popular with "teams of average-proficiency developers", while ObjC is "more popular" with "high-proficiency developers" (I'd love to hear how the proficiency level of the developers in question was measured), then I think this statement is better left out of the article. --Allan McInnes (talk) 22:11, 25 May 2006 (UTC)

Agreed. It's highly POV.

Comment by DarelRex: I do not object to Allan's removal of this statement from the section I added - that seems reasonable and fair. For the record, by "high-proficiency developer" I meant a developer who can write large projects in straight C without creating a buggy, poorly organised nightmare. Most developers employed by large corporations for in-house apps need the restrictions of object-orientation (e.g. C++) to prevent that from happening. (Today it would be Java, which is even more restrictive.) That said, my section does seem much more professional and objective with the statement removed. Thanks, Allan. --DarelRex 17:42, 26 May 2006 (UTC)

Yes but then you have to defend C++ as being 'object oriented' which of course is impossible. Smalltalk creator Alan Kay has been very explicit in that matter as you know. C++ is not object oriented; it is a hybrid language which can achieve certain object oriented features. 'Big difference'.
You may well be right about the quality of in-house developers. My point was that unless someone can produce a reference that shows that
  1. C++ is more popular for big in-house corporate projects than ObjC
  2. ObjC is more popular than C++ for commercial or independent apps
  3. In-house programmers are "average-proficiency" (by some measure) while commercial/independent programmers are "high-proficiency"
then your claims, while they may be well-grounded in reality, are not verifiable.
Another alternative would be to find an article where someone makes the same claims that you have, at which point it would be reasonable to add a statement to the effect that Person X claims that C++ has been popular for big, in-house, corporate projects, written by teams of average-proficiency developers... — this makes the claims a verifiable statement of someone's opinion. --Allan McInnes (talk) 18:39, 26 May 2006 (UTC)
This is all still extremely POV and even moot as Objective-C has not enjoyed the widespread use of C++, making such comparisons impossible. Yet NeXT and Apple themselves have used this language to build an impressive set of frameworks and although Jobs argued his NeXT programmers were 'top drawer' the same cannot necessarily apply at Apple where legacy programmers from the 'Apple' days stayed on and learned the language for better or for worse. Objective-C was also popular on Wall Street in the 1990s and financial applications aren't going to be the most trivial ever. Further: looking at matters from a mathematical or abstract point of view one would be forced to argue Objective-C is better suited to the nontrivial project. And this seems to be born out in recent empirical studies. Finally: any experienced system architect or system engineer is painfully aware of how C++, rather than being a boon for 'run of the mill' IT departments, invariably leads to drawn out troubleshooting for bugs of all degrees of insidiousness. Far from being merely an unsubstantiated opinion which could in theory be correct it's more likely an opinion which is dangerously incorrect.

Comparision to C++

"In C++, object-oriented is a coding style intended to force a certain kind of organizational structure on the sourcecode. The use of straight C in a C++ project is discouraged, and not all C syntax is even supported by the compiler. The C++ syntax looks very similar to C, but this is not considered confusing, because the developer is expected to "unlearn" C and do everything in the new, C++, object-oriented way. C++ comes with a large class library of very general-purpose classes, which is treated as part of the language; developers are expected to know it, use it, and subclass it.

In a C++ compiled executable, the method names are gone, and the machine code is not significantly different than that generated by a C compiler. Further, the objects are not truly independent entities, but rather temporary constructs of the object that created them."

I really don't understand the last sentence.

"C++ comes with a large class library of very general-purpose classes" - I thought it comes with a library of template classes, and programmers aren't encouraged to subclass them, but to instantiate them. I rather think of C++ as a tool for _generic_ programming, more than one for OO. —The preceding unsigned comment was added by 141.3.26.29 (talkcontribs) 07:57, 31 May 2006 (UTC)

Indeed. This section was clearly written by someone who doesn't know C++ at all (I don't think there is a single class in the standard library that programmers are meant to inherit from, for instance). I've just removed the section, because I don't have anything useful to say about the topic, and that's better than just leaving bogus information sitting there. 71.68.75.61 07:17, 2 June 2006 (UTC)
I have added this section back in after it was entirely removed by the above, anonymous user. I have, however, made changes to it in response to the specific points of criticism that were offered in the above text. --DarelRex 13:54, 6 June 2006 (UTC)
I've rewritten the section entirely to conform to what C++ is actually like. I was hesitant to do this before and removed the entire section because I don't really know Objective C. 71.68.75.61 12:31, 9 June 2006 (UTC)
I think the rewrite is okay, but there was some good information about Objective-C that was removed from the section. Now it has a pretty heavy C++ focus, which might not be the best approach in an Objective-C article. – Mipadi 12:37, 9 June 2006 (UTC)
Thanks, Mipadi, for your wording edit. Looks good! --DarelRex 12:50, 7 June 2006 (UTC)
Glad I could help. :) – Mipadi 15:54, 7 June 2006 (UTC)

The "philosophical" comparison seems misleading, by not questioning C++ at all with regard to object-oriented programming (see opinion of Alan Kay), yet not allowing that ObjC is capable of generic programming or meta-programming. I may be confusing dynamic polymorphism with generic programming, but ObjC allows NSArray to contain objects of any type, and class clusters allow clients to access any number of distinct classes from a single interface. Perhaps NSArray or class clusters have too little in common with generic programming, but a balanced comparison would fit in the dynamic capabilities of ObjC which are missing from C++, or at least point out that C++ is only capable of certain object features. As for meta-programming, I think that InterfaceBuilder and nibs may offer the same rapid development outcome without the excess baggage of generated code. Again, I may not have the complete picture with regard to the comparison, but I stand by my general opinion that the philosophical comparison is rather slanted towards C++ without good reason.BrianWilloughby (talk) 14:43, 21 June 2010 (UTC)

e.g. the "philosophical" comparison should point out that C++ is not capable of dynamic typing, whereas ObjC can handle both dynamic typing and static typing, under control of the programmer. BrianWilloughby (talk) 12:28, 22 June 2010 (UTC)

Obj-C vs. Obj-C libraries

Unlike C, Objective C does not specify any class libraries.

The root class Object and the metaclass Class are defined and the runtime provides for them, but semi-automated garbage control methods like retain and release are implemented by NSObject and not by Object. These methods were introduced with OpenStep (in NeXTStep we had alloc and free, remember?). Similarly with archiving, etc. I don't have any more time for this article tonight, but it needs some attention in this matter. It is possible that some of that information should move over to OpenStep instead...

Another thing that needs doing is dealing with the language specification. Things like formal protocols maybe should move toward the end, while really powerful and distinguishing features like Categories and poseAs: should be featured. Anyway, the article is a great start, but a bit of tightening would really make it shine. -- cmh 01:49, 2 June 2006 (UTC)

Archiving is possible in bog-standard ObjC. Object provides for read: and write:. I don't think your changes are entirely correct re typing either: specifically, "All 3 statements are equivalent at runtime", but I can't think about this for too long at the moment, so I'll get back to this properly at some other time. Dysprosia 04:56, 2 June 2006 (UTC)
Fair enough on the archiving... I'd forgotten about read/write. Note, though, that archiving as a technical usage generally refers to the NSArchiver mechanism. Perhaps calling it serialization would be better? As for the runtime equivalence issue, go ahead and try it... The compiler doesn't put typechecking into the code. All object typing is advisory to the compiler only. -- cmh 14:30, 2 June 2006 (UTC)

I'll phrase this as a question, but I think I know the answer. When people say that ObjC does not specify a class library, does that just mean that the language specification does not document any library conventions? I always learned that while standard C mentions printf() in the language documentation, the compiler itself does not provide printf(). You still have to obtain the libraries separately, either as source or as an object file (admittedly, they're pretty much always there already). Same with C++ ... the standard library is still technically separate from the compiler, and thus somewhat separate from the language. I guess ObjC carries this to the extreme by completely failing to mention anything about Object or NSObject in the language specification. My real question is how do you describe this concisely and accurately to the uninitiated? BrianWilloughby (talk) 14:17, 22 June 2010 (UTC)

POV

I marked the Dynamic Typing section with a NPOV marker because of the last paragraph in the section. The words "sadly" "annoying" and just one too many uses of the second person make it lose its neutral point of view. Matthew Stuckwisch 04:36, 28 June 2006 (UTC)

I think you're missing the point: "sadly" doesn't imply POV, it means that a factual problem is being illustrated, that casting does break the discipline of static typing and this is not a Good Thing. The sentence should probably be worded for stylistic reasons, though. Dysprosia 04:58, 28 June 2006 (UTC)
I think YOU are missing the point. Any experience in programming with this language would make it clear why things are done in this way - why in fact this is truly a Good Thing™.
In an article about a movie, you wouldn't write "Sadly, a sequel was never finished, which was an annoyance because the first one didn't fully explain to you what happened and you were left wondering why X did Y", it would simply say "Though the film ended without fully explaining the reasons for X's doing Y, a sequel was never finished, leaving it forever unexplained". Perhaps it is more a stylistic issue, but since I've seen people in the past expound both static and dynamic typing as A Good Thing™ in X language, it seemed a biased POV to me. —The preceding unsigned comment was added by Guifa (talkcontribs) 05:23, 28 June 2006 (UTC)
Your analogy is incorrect, and it's not about static and dynamic typing, the sentence is about casting. But we both agree the sentence needs to be rewritten, so there's no need to argue this further. Dysprosia 07:04, 28 June 2006 (UTC)
To elucidate some of the trouble with refining this article: you find very few programmers truly proficient in Objective-C at all - in comparison to the wide number who express 'some' proficiency in C++. Of the latter only a subset really understand the underlying C.

Claims in analysis section

I edited the paragraph "Categories and protocols may be used to provide many of the benefits of multiple inheritance, without many of the disadvantages, such as extra runtime overhead and binary incompatibilities." by removing the vague (POV?) claims about "the many disadvantages of mutiple inheritance". Mikademus 08:35, 7 July 2006 (UTC)

GC and OC

As far as I know, apple has not announced GC. While it may have been brought up at WWDC, with whatever betas, these are under NDA and so this fact is not verifiable from reliable sources. Thus I have attached the fact template. We should not be in a rush to include this fact in Wikipedia, there will be time enough to do so after it is released. Likely, if no reliable source can be found, this information should go for now. -- cmh 04:30, 15 August 2006 (UTC)

Garbage collection has been publically announced on the Apple web site as part of the feature set for Objective-C 2.0. ("Enjoy modern garbage collection, syntax enhancements, runtime performance improvements, and 64-bit support." [1]) —The preceding unsigned comment was added by Shunpiker (talkcontribs) 18:07, 19 August 2006 (UTC)
Good enough for me. Thanks. -- cmh 19:42, 19 August 2006 (UTC)

Overloading clarification

Function or method overloading in the same class (a la C++) is not possible, as is shown in the following code:

@interface test
{
}
- (id)init:(int)i;     // line 4
- (id)init:(double)x;  // line 5
@end

@implementation test
- (id)init:(int)i
{                      // line 10
}
- (id)init:(double)x
{                      // line 13
}
@end

gcc 4.0.1 (from latest Apple development tools) gives the following errors:

test-overloading.m:5: error: duplicate declaration of method '-init:'
test-overloading.m:13: error: conflicting types for '-[test init:]'
test-overloading.m:10: error: previous definition of '-[test init:]' was here
test-overloading.m: In function '-[test init:]':
test-overloading.m:13: warning: conflicting types for '-(id)init:(double)x'
test-overloading.m:4: warning: previous declaration of '-(id)init:(int)i'

Engelec 19:59, 29 August 2006 (UTC)


I can verify this. The comon idiom is to write code like so:

@interface test
{
}
- (id)initWithInt:(int)i;     // line 4
- (id)initWithDouble:(double)x;  // line 5
@end

The logic with this design is that it is very clear what is intended and it prevents errors caused by type mismatches. One could argue that this route leads to needlessly verbose code. In practice this isn't a problem. From what I can tell this hasn't been added to the language because it simply isn't needed. —The preceding unsigned comment was added by Harveyswik (talkcontribs) 07:46, 16 October 2006 (UTC)

I'm sure there's still the possibility of function overloading in other cases, but I haven't been able to test anything. I could be wrong, however. Dysprosia 08:03, 16 October 2006 (UTC)
categories provide function replacement, but not exactly function overloading. A proficient run-time hacker could use categories or other aspects of the run-time to implement function overloading (at run-time, of course, not at compile time). BrianWilloughby (talk) 14:21, 22 June 2010 (UTC)

Infobox

Could someone who knows ObjC well enough provide a "programming language" infobox? —The preceding unsigned comment was added by 85.126.110.203 (talkcontribs) 15:07, 23 September 2006 (UTC)

Could someone who knows wikipedia well enough direct me on how to do this? —The preceding unsigned comment was added by Harveyswik (talkcontribs) 07:41, 16 October 2006 (UTC)

Dynamic Typing

I object to the sample code provided on the grounds of correctness.

- setMyValue: (id <aProtocol>) foo;
- setMyValue: (NSNumber*)foo;

This is incorrect because these two lines can't exist together like this in the same header file. error: duplicate declaration of method '-setMyValue:'

This is bad style because the ObjC way to set values is to use the name of the value. It is best to give a concrete examples of this.

- setDelegate: (id <aProtocol>) anObject;
- setCount: (NSNumber*)count;

—The preceding unsigned comment was added by Harveyswik (talkcontribs) 08:14, 16 October 2006 (UTC)

In context, there are two seperate examples "In the first statement, the object must conform to the aProtocol protocol, and in the second, it must be a member of the NSNumber class." This doesn't imply that each statement is to be used together. Dysprosia 08:39, 16 October 2006 (UTC)

Forwarding

The sample code in the forwarding section is out of date for both MacOS X and GNUstep.

Instead, create a sample derived from the one <a href=http://www.gnustep.org/resources/ObjCFun.html>here</a>

- (void) forwardInvocation: (NSInvocation*)anInvocation
{
  if ([anObject respondsToSelector: [anInvocation selector]])
    return [anInvocation invokeWithTarget: anObject];
  else
    return [self doesNotRecognizeSelector: [anInvocation selector]];
}

—The preceding unsigned comment was added by Harveyswik (talkcontribs) 08:19, 16 October 2006 (UTC)

The article is not about OS X nor GNUstep, it's about Objective-C. Just because Cocoa/OPENSTEP provide different library functions to perform forwarding, doesn't mean that it's somehow a part of Objective-C. It isn't. Dysprosia 08:35, 16 October 2006 (UTC)
You're right, I was wrong. The sample code is not out of date, it's just irrelevant for most people trying to do forwarding in Objective-C.

There are probably on the order of 10 existing implementations using @selector(forward::), everyone else uses @selector(forwardInvocation:). It's certainly true that @selector(forwardInvocation:) is not part of the language but it's also true that forwarding messages in Objective-C is done with the API provided by the base-class, not the language defined API. This should at least be mentioned.

Also, the comments are wrong in this code from the Forwaring section:

- (retval_t) forward: (SEL) sel : (arglist_t) args; // with GCC
- (id) forward: (SEL) sel : (marg_list) args; // with NeXT/Apple systems

Both examples work with GCC, just with different runtimes. The first works with the GNUstep runtime, the second with Apple Computers private runtime. In fact, I don't know of any other compiler or any other runtimes than those I just mentioned. Note that in the case of Apple this has nothing to do with Cocoa other than that the frameworks depends on the private runtime.

However, this information is really only usefull to those implementing a base-level framework(GNUstep, Cocoa, etc.) or a HOM implementation (most of those I've found use the NSProxy API). It's of little interest to anyone writing Objective-C code based on one of these base-level frameworks or using a HOM implementation because it's too low-level. —The preceding unsigned comment was added by Harveyswik (talkcontribs) 20:40, 16 October 2006 (UTC)

.m vs. .mm

I find it really strange that the article makes absolutely no mention of the difference between using the .m and .mm extensions for your implementation files. From [2], Apple’s Objective-C compiler allows you to freely mix C++ and Objective-C code in the same source file. This Objective-C/C++ language hybrid is called Objective-C++. With it you can make use of existing C++ libraries from your Objective-C applications. Note that XCode requires that file names have a “.mm” extension for the Objective-C++ extensions to be enabled by the compiler. —lensovettalk – 02:16, 25 January 2007 (UTC)

file extensions merely set the initial default. Xcode has a popup in the file inspector which allows you to select the language. I've used this a few times to quickly check whether I should rename a file to fix something, because you can make the same thing happen without actually renaming the file (which could piss off CVS). In other words, this is a feature of Xcode and the operating system or file system, not of Objective C itself, unless you're talking about a particular compiler (in which case there are command line options that Xcode is using to change the default behavior). BrianWilloughby (talk) 14:30, 22 June 2010 (UTC)

Dot notation

I was under the impression that the dot notation could only be used to access properties, and not for all method calls. Ddfreyne 13:05, 27 May 2007 (UTC)

Correct; however, I believe that it will be available for all method calls (like Java) in Obj-C 2.0 —lensovettalk – 18:59, 27 May 2007 (UTC)

I've been tracking Objective C 2.0 for months, and nothing that I have seen, including GNU GCC repository code updates from Apple, indicates that dot notation will be available for anything but properties. In fact, doing dot notation for methods would be a major change and causes all sorts of problems like how to handle methods with more than one parameter. So I'm going to try out Wikipedia's famous editing abilities and use my authorative knowledge of Objective C 2.0 to correct the article by deleting this section. - steve

Rephrasing of garbage collection section

The previous version of the garbage collection section made it sound like "garbage collection" and "reference counting" where equivalent terms, which they are not. I rephrased it to remove this implication, but in the process also removed the mention of reference counting.

If the intent was originally to communicate that the garbage collection implemented for 2.0 used reference counting, please someone rectify this or let me know where I can read about it. I did not find a lot of concrete information when I attempted to Google around, and I am not personally aware of the details.

--Scode 11:28, 12 August 2007 (UTC)

Analysis of the language

"As of 2007, all Mac OS X classes and functions in the Cocoa programming environment are prefixed with "NS" ..."

This isn't quite right. What about CoreFoundation? Perhaps we should distinguish the "higher level" parts of the Cocoa frameworks from "the Cocoa programming environment" when making such a statement. It would also be prudent to distinguish, say, the AddressBook and CalendarStore frameworks from "the Cocoa programming environment" since they also don't use an "NS" prefix (but "AB" and "Cal" respectively). —Preceding unsigned comment added by 128.231.88.5 (talk) 20:03, 25 February 2008 (UTC)

CoreFoundation is not Objective C. It is a standard C API which bridges to Objective C object instances. I don't think it belongs here. BrianWilloughby (talk) 14:33, 22 June 2010 (UTC)

User Manual Not A Article

This article is a bit ridiculous. First it is too long. Second it is too technical. It's really not an article at all. It is actually the start of a user manual. —Preceding unsigned comment added by 75.210.51.228 (talk) 14:57, 12 April 2008 (UTC)

I agree, but is this not the perfect use for a wiki??? —Preceding unsigned comment added by 69.110.27.182 (talk) 18:00, 30 September 2009 (UTC)
An instructions wiki, sure, but this is an encyclopedia, not a repository of manuals. 206.75.146.60 (talk) 09:51, 2 May 2010 (UTC)
Agreed. I love Objective C, but there is too much detail in the examples. There are other wikis available for detailing Objective C - you could even start your own on another site! BrianWilloughby (talk) 14:35, 22 June 2010 (UTC)

Protocols v. Java Interfaces

From the section on protocols:

The Objective-C concept of protocols is different from the Java or C# concept of interfaces in that a class may implement a protocol without being declared to implement that protocol. The difference is not detectable from outside code.

I can't speak to C#, but I don't think this is accurate in the case of Java. Just as you can implement a protocol in an Objective C class without declaring the protocol, you can implement an interface in a Java class without declaring the implementation. This approach might be less useful in Java due to the greater use of static typing, but it certainly can be done.

I'm not sure what is meant by the difference (presumably between a declared protocol and an implemented but undeclared protocol) not being "detectable from outside code". It's my impression that a class which implements a protocol but does not declare the protocol will not return true for a conformsTo protocol test. Perhaps this is what is meant by detecting the difference "from inside code". What could be meant by detecting the difference "from outside code"?

I believe your impression is wrong. -conformsTo: is a run-time check, not a compile-time check, so the difference would be lost after compiling. Perhaps Java maintains the distinction at run-time. BrianWilloughby (talk) 14:39, 22 June 2010 (UTC)

Naming in lead

Article leads with "Objective-C, often referred to as ObjC and sometimes as Objective C or Obj-C..." Is this really necessary? Objective-C is the correct name. ObjC and Obj-C are both obvious short forms. Objective C is just plain wrong. I recognize we want the redirects to be obviously pointing to the right article, but I don't think the lack of a hyphen is going to cause anyone any great mental anguish. --Steven Fisher (talk) 23:45, 29 August 2008 (UTC)

Ownership

Ownership of and licensing terms for this language are crucial issues that need to be included - especially their histories. Objective-C was not patented into the public domain as for example C was. NeXT acquired a licence to even use the language. NeXT acquired the ownership of Objective-C first in 1995. What is the nature of these agreements? To what extent has Objective-C been free to use - or even free to licence - over the years? What are the current terms of licensing? Apple ship Objective-C with their ADC tools for free; similar tools for NeXTSTEP cost $10 K. There are also repeated suggestions institutions such as MIT went with C++ because Objective-C was not available at attractive terms. It would seem these details are deliberately not forthcoming but in everyone's interests it would be good if Wikipedia researchers could get to the bottom of this. —Preceding unsigned comment added by 90.5.7.87 (talk) 01:28, 1 September 2008 (UTC)

In 1991, the purchase of NeXT hardware included the NEXTSTEP 2 OS and the entire development environment for free. Granted, the hardware was several thousand dollars. At the time, equivalent Sun hardware cost exactly the same as NeXT hardware, but certain Sun DSP development tools cost $3,000 extra. I cannot speak to pricing between 1988 and 1990, or after NeXT stopped selling hardware. It's possible that they once charged $10K for ObjC (maybe for source code?), but I don't recall ever seing a price list with that figure on it (and I've kept all of the price lists I obtained before purchasing my first NeXT).
I believe that, at the time, problems with Objective-C included that nobody had a run-time, and that there were initially no alternate compilers for the language. BrianWilloughby (talk) 13:42, 22 June 2010 (UTC)

Sorry to interject - but this article reads like an attack / defense of C++/Java. Wish we could focus on the attributes of Objective C. I someone wants to defend java or C++ - create a new wiki page or do so in the foot notes. BTW: I'm not a big fan of Objective C - I like strong typing. I believe things should fail at compile time - not at runtime, or we will have javascript hell. Dynamic binding is not an excuse. But anyway - please, let's focus on Objective C.

173.70.96.132 (talk) 22:54, 5 February 2009 (UTC) Raf.

I agree that this article sounds like an attack. Most comparisons are phrased in terms of what C++ offers, as if that were the metric for all languages. I was not familiar with the terms generic programming and metaprogramming until reading here that C++ has them and ObjC doesn't - yet the page for generic programming explains that it is implemented differently in each language, allowing for dynamic typing in ObjC to meet the criteria, and the page for metaprogramming indicates that reflection is a key strategy - reflection being a feature that is vastly stronger in ObjC than C++. It might make more sense to use SmallTalk as the reference.
By the way, Objective C is perfectly capable of strong typing at compile time, it just requires good developer habits when declaring variables and methods. There should be an Elements of Style for ObjC which exemplifies this fact. BrianWilloughby (talk) 13:42, 22 June 2010 (UTC)

Dynamic Compilation in Java

This mechanism allows messages to be sent to an object defined first at runtime - something statically typed languages such as C++ and Java are incapable of per the current standards for both languages.

Java can indeed define brand new objects and classes during runtime.

It can even accept dynamic input, turn this into code and apply the full power of the platform's optimizer to this new code.

For one example see: http://fivedots.coe.psu.ac.th/~ad/jg/javaArt1/index.html

Hcobb (talk) 17:19, 11 October 2008 (UTC)

The example you cite — involving adaptive compilation — is fundamentally different from what Objective-C provides. For example, Mac OS X provides no facilities for just-in-time compilation of C code. However, the runtime is highly dynamic, and allows classes to add and/or modified at runtime. (See the runtime reference for details.) For example, PyObjC uses this to map a Python class to an equivalent, dynamically defined Objective-C class. To my knowledge, the Java reflection APIs merely provide the ability to introspect a class but not modify it.
-- Dan Villiom Podlaski Christiansen (talk) 01:49, 1 February 2010 (UTC)

C97?

The article currently (Apr. 19, 2009) says "If you are translating from C++/C97 the above code is somewhat equivalent to:". I assume that "C97" is supposed to be "C99"; I can't find any reference to a version called C97. Also, I don't believe C99 has the OO features the following code segment shows, so I'm going to just delete the reference to C. Someone correct it if I'm wrong. 71.13.148.220 (talk) 19:14, 19 April 2009 (UTC)

"Dynamic" or "Static" typing?

The "Typing Discipline" in the infobox says "Static", however, if you go to the page and read the section on "Dynamic" typing, Objective-C is listed as an example of a language that is "Dynamic" typing. One of these must be at least partially wrong - either it's a combination and should be listed as such in the other article, or, it should be listed as "Dynamic" or a combination here in the infobox. I'm very new to Objective-C and don't know the answer to this question, does anyone here know how we can fix this discrepancy? -- Renesis (talk) 16:30, 7 May 2009 (UTC)

It's hybrid. The question is -- is ObjC really weak typed? I don't think so. Can someone demonstrate why?
The type system in Objective-C is completely static, like C. There is no type coercion and no polymorphism of operators. On the other hand, a great chunk of the object system - that is, the message passing system, by which objects move control or data between each other - uses late binding, so you get no guarantee at compile time about the type of the return value, like you do in C++, Java etc. On the other hand, object types for variables (or more accurately, object pointer types) are static, just like the primitive types. "Weak typing" is a kind of a wooly phrase but I would propose that it doesn't really describe how Objective-C works; and neither, really, does "Dynamic typing". 92.233.195.172 (talk) 15:38, 17 July 2009 (UTC)
That is not entirely accurate. Objective-C is dynamically typed, but with optional static type checking. (Refer to Apple's documentation for details.) The core C types are statically typed with no dynamic type checking whatsoever, as is common for C. Objective-C objects can be statically typed — by using class pointer types instead of an unqualified type of id — but this information is disposed of during compilation. The runtime type model beyond that is essentially laissez faire; methods may or may not, at their discretion, check whether an argument implements a certain type or protocol.
--Dan Villiom Podlaski Christiansen (talk) 01:37, 1 February 2010 (UTC)
What is the definition of "strong" typing? It would seem that Objective C can be strongly typed at compile time. BrianWilloughby (talk) 14:44, 22 June 2010 (UTC)
Objective-C uses Duck typing, especially when used as a messaging system so the thing being called might not even be compiled at the same time. Hcobb (talk) 15:49, 22 June 2010 (UTC)
Thanks for the link. The Duck typing article mentions that ObjC uses (id) for these case, but it's also common to use (MyObject *) instead of (id) - What I'm asking is whether ObjC is also "strongly" typed in that case. I know ObjC is not strongly typed when using (id) BrianWilloughby (talk) 10:00, 29 June 2010 (UTC)

Analysis "of the language"

The first para of Analysis of the language contains comparisons to Smalltalk that seems to have little to do with the respective languages, but instead available implementations of the languages. This is 1. not fair, 2. not pertaining to language, unless it can be traced back to the language definitions, such as "Smalltalk requires", "Objective C is defined so that necessarily", etc.. If such tracks are lacking, then such statements should be placed in a section Available implementations, and such. All too often, however, comparisons that aren't about language issues tend towards this-or-that-PL-advocacy, so care about comparing real life implementations should IMHO be taken. ... said: Rursus (bork²) 16:02, 5 June 2009 (UTC)

Enhanced Glossary / Code line translator

I am a beginning programmer in Objective C, and am having a difficult time deciphering code snippets. I would like to create a new section that contains simple lines of code or snippets, and provides a 'simple' English (or other) language translation, as well as description of what is be written. I was going to create my own wiki for this, but thought it might be an appropriate section for this article. Any thoughts or suggestions? —Preceding unsigned comment added by 69.110.27.182 (talk) 17:45, 30 September 2009 (UTC)

Stuff removed from Boolean data type article

The following section was removed from the article Boolean data type:
begin removed text



Objective-C provides a type BOOL, and macros YES and NO. Since Objective-C is a superset of C, C language semantics for booleans also apply.



end removed text
Is there a place for this text in the Objective-C-related articles? Perhaps in the Wikibook? Thanks, and all the best, --Jorge Stolfi (talk) 23:48, 30 December 2009 (UTC)

What is IMP?

In the Messages section, it says, Subsequent calls are IMP cached and 50% faster than the C++ virtual method call.[2]. We need an explanation of what IMP is (or a link to one). -- RoySmith (talk) 20:50, 31 January 2010 (UTC)

I attempted to fix this by mentioning it a bit earlier in the article. Does it suffice? Dan Villiom Podlaski Christiansen (talk) 01:23, 1 February 2010 (UTC)
OK, I get it now. IMP = Implementation. Thanks. -- RoySmith (talk) 02:43, 1 February 2010 (UTC)

Slight inaccuracy in C++ comparison

I think there's a minor issue of terminology in the "Syntax" section, under "Messages". It's where a comparison is made to C++. An example suggests that you would use the following code in C++ for "sending the message method to the object pointed to by the pointer obj":

obj.method(parameter);

Strictly speaking, "obj" isn't really a pointer in this context. If it was a pointer, you'd need the following syntax instead:

obj->method(parameter);

I know different programming languages use terms differently, so maybe I'm just being pedantic, but perhaps a correction here would be helpful?

Elusive Pete (talk) 20:55, 1 March 2010 (UTC)

Extension methods

It says the runtime binding of "methods" in Objective-C is similar to C# Extension Methods. I don't know Objective-C but I do know C#. The latter are purely a compiler feature that allow methods to be added without modifying the class (or even owning it). They are linked up at compile time and the binary IL is the same as if they were regular methods. So there is no runtime aspect at all. If that means that this analogy is bad, could someone who knows that please fix it, and perhaps keep the C# observation but make it a contrast instead of analog. Cheerlessbox (talk) 05:11, 28 July 2010 (UTC)

Not Neutral Point Of View

This paragraph sets up a strawman:

"When implementing container classes using statically-typed languages without generics (like Java prior to version 5), the programmer is forced to write a container class for a generic type of object, and then cast back and forth between the abstract generic type and the real type. Casting, however, breaks the discipline of static typing. For instance, putting in an integer and reading out a string will produce a runtime error."

Nobody argues that. That's one of the many reasons generics were added to Java waaaay back in 2004.

Furthermore, the paragraph goes on to say:

"This problem is addressed in, for example, Java 5 and C# with generic programming, but then container classes must be homogeneous in type. This need not be the case with dynamic typing."

without defending *why* container classes being homogeneous is a bad thing (which it implies), and without--and this is the worst offense--mentioning that interfaces in Java and C# can be the type with which a generic is instantiated, in which case *any implementing instance of the interface* can be added to the container. Meaning heterogeneous. Meaning the section is essentially wrong.

Collections of interfaces in Java and C# allow polymorphic variation while preserving type safety *at compile time*, which is more than can be said for dynamic typing, which this paragraph holds up as a virtue. —Preceding unsigned comment added by 66.14.154.3 (talk) 08:43, 23 December 2010 (UTC)

Messaging Speed

The discussion comparing the speed of sending a message vs. a method invocation only considers the time to resolve the target, and not the time to marshal arguments. Argument marshaling can be quite time consuming; the conclusions are questionable without an analysis of this. NJ-JohnE (talk) 14:41, 29 June 2011 (UTC)

Do you have any actual benchmarks to back this up? Unless the difference has been shown to be significant enough to affect real-world optimization, I don't think it's worth mentioning. (By the way, the source cited, though not authoritative at all, shows a minuscule difference in an actual benchmark.) In fact, even before I read your comment, I had come to this Talk page just to raise this question: Is the section comparing C++ virtual method calls to ObjC message sending even worth including? I'm not trying to raise the debate of optimizing before or after profiling or anything like that, I just think that the scale is far too small to consider for nearly all purposes. We're talking about a difference of half a nanosecond (according to the source cited in the article). Even for such a common operation, that is such a small amount of time that I think it's misleading to present this as an legitimate point of comparison between the two languages. And why are we implicitly comparing Objective-C and C++ outside of a section that clearly indicates it's comparing them, anyway? As if the article were actually a critique of one or the other, rather than a set of information on Objective-C. At best, I would simply remove these two sentences, because I think they mislead and confuse without adding anything useful in return. Barring that, they should at least have some mention of the scale involved (e.g., "are faster than the C++ virtual method call in some implementations, by approximately half a nanosecond."). If this seems superfluous, then... why isn't the whole paragraph? Jrajav (talk) 13:07, 19 April 2012 (UTC)
Not sure if five days is really long enough, but I've deleted the paragraph in question. If anyone objects or otherwise has something to add, feel free to revert it, but PLEASE mention it here for further discussion. I personally think it's superfluous for the reasons I've already mentioned. Jrajav (talk) 16:22, 24 April 2012 (UTC)

Dubious

There is already an unrelated discussion on this statement in the #Protocols v. Java Interfaces section. I started a new section to properly document this dubious claim.

The statement:

The Objective-C concept of protocols is different from the Java or C# concept of interfaces, in that a class may implement a protocol without being declared to implement that protocol. The difference is not detectable from outside code.

is wrong because a class that does not explicitly declare that it implements a protocol, will fail the conformsToProtocol: test. So it does not truly implement that protocol, and the difference is detectable from outside code. — Preceding unsigned comment added by 208.80.119.67 (talk) 04:10, 20 July 2011 (UTC)

By adding a category that declares conformance to a protocol, a class can conform to a protocol (conformsToProtocol: returns YES) without publicly declaring it. Or it could add the protocol at runtime. Whether this is relevant to the article remains to be seen. 24.6.37.253 (talk) 06:59, 10 December 2011 (UTC)

Please take a look at [3] where Patrick Naughton writes: "I'm pretty sure that Java's 'interface' is a direct rip-off of Obj-C's 'protocol'" — Preceding unsigned comment added by 93.220.113.109 (talk) 17:20, 2 October 2011 (UTC)

Is mention of GNUstep appropriate here?

In the interest of "be[ing] not too bold," I thought I'd ask about the appropriateness of changing a bit of text here before I did it, more specifically to mention the use of GNUstep as a possible replacement for Cocoa. (This, after all, is its purpose: as a free (libre) software replacement for non-free Cocoa.) Can I change this:

Generic Objective-C programs that do not
use these libraries can also be compiled
for any system supported by
[[GNU Compiler Collection|gcc]] or
[[Clang]].

into this:

Generic Objective-C programs that do not
use these libraries can also be compiled
for any system supported by
[[GNU Compiler Collection|gcc]] or
[[Clang]], although programs which only
require the Cocoa libraries may (perhaps with
modification) be able to be compiled with
[[GNUstep]] instead.

or would that be incorrect? — Preceding unsigned comment added by 12.218.76.10 (talk) 23:05, 13 January 2012 (UTC)

IIRC Gnustep is not a compiler, so that would be indeed incorrect. 1exec1 (talk) 10:53, 17 January 2012 (UTC)

IS THIS SENTENCE RIGHT?

  • The text field discovers whether the delegate implements that method (via reflection) and, if so, calls the delegate's method to support the auto-complete feature.
    • Maybe The text field discovers whether the delegate implements that method (via reflection) or, if so, calls the delegate's method to support the auto-complete feature. — Preceding unsigned comment added by 175.253.27.227 (talk) 14:58, 23 January 2012 (UTC)

On the rise obviously

Not, that I'm any less skeptic towards Objective-C than just any PL, but THIS LINK indicates Objective-C is on a steep ascendancy. There must be some market reason behind this, prob some product from Apple Inc.. What is it? Rursus dixit. (mbork3!) 12:23, 3 May 2012 (UTC)

iOS applications; see iOS_SDK and App Store (iOS). Rostz (talk) 17:34, 3 May 2012 (UTC)
THX·10³! Rursus dixit. (mbork3!) 15:22, 4 May 2012 (UTC)

Opinions and factual errors in the "Analysis" section

This paragraph is particularly troubling:

"Many programmers dislike garbage collected languages because of the runtime performance tradeoffs. Objective-C applications commonly run with garbage collection. Apple introduced Automatic Reference Counting (ARC) in 2011 as an alternative memory management mechanism. With ARC, the compiler inserts retain and release calls automatically into Objective-C code based on static code analysis. The automation relieves the programmer of having to write in memory management code. ARC also adds weak references to the Objective-C language. While ARC removes the need for garbage collection and manually memory management, it is only available with Apple's XCode compiler."

Sentence by sentence:

"Many programmers dislike garbage collected languages because of the runtime performance tradeoffs."

First of all, who are "many programmers", and why do we care? I fail to see the relevance to the article. This isn't an opinion piece - it's an encyclopedia.

"Objective-C applications commonly run with garbage collection."

Isn't this a feature of the runtime, not the language?

"With ARC, the compiler inserts retain and release calls automatically into Objective-C code based on static code analysis. "

Isn't this a feature of the compiler, not the language?

"ARC also adds weak references to the Objective-C language."

It's probably worth noting what keywords were added to the language to support ARC, but only in the context of the language itself. Saying that "ARC adds weak references to the Objective-C language" is back-to-front. "Objective-C version ____ added the following keywords to support a compiler feature called ARC:" would be more accurate.

"While ARC removes the need for garbage collection and manually memory management, it is only available with Apple's XCode compiler."

This is either factually incorrect or misleading at best. First of all, it's spelled Xcode, not "XCode". Also, Xcode uses the LLVM compiler - the source for which is freely available - and Objective-C programs can be compiled without Xcode at all - so I fail to see how ARC has anything to do with Xcode in the least. — Preceding unsigned comment added by Stevenewright (talkcontribs) 20:16, 23 July 2012 (UTC)

Discussion: Method description should be method description, not C-programmer tute

When methods are discussed in the implementation section of this article, there is a change in tone/ purpose. Instead of being an informative article on Objective-C, it starts being instead a tutorial for a C programmer on how to use Objective-C. In comparison, in an article on President Harding, you wouldn't say, "He was born in the same state as President Lincoln, whose home state you're all familiar with." Most people reading about Harding know about Lincoln, just as most people reading an Objective-C page know about C.

Request: could someone put the actual syntax for a method in the description of methods. I was following a tutorial on another site and needed to come to this specific information, but it wasn't in your article. I don't object to the very helpful example in Objective-C, I don't object to there being an additional purpose of comparing to C (which no doubt will help many readers), but the Objective-C article should at a minimum first explain Objective-C.

Respectfully submitted, Pterandon (talk) 16:21, 14 September 2012 (UTC)Greg M. Johnson

What libraries?

The introduction ends with "Generic Objective-C programs that do not use these libraries can also be compiled for any system supported by GCC or Clang." What libraries are "these libraries"? This is the first mention of libraries in the article. I suspect something got removed from the introduction and this sentence was not updated to comply with that removal.

Wjl2 (talk) 16:14, 6 November 2012 (UTC)

The article seems to have been clarified. The Anonymouse (talk • contribs) 17:53, 26 November 2012 (UTC)

No mention of "code blocks" (a.k.a. closures)

Resolved

This new language feature (see: http://developer.apple.com/library/ios/#documentation/cocoa/Conceptual/Blocks/Articles/00_Introduction.html) is not mentioned in the article. Why not?

Tzadik (talk) 17:47, 26 November 2012 (UTC)

Isn't "blocks" a C language feature? I can't seem to find any information in the C article either, but Block (programming) exists without any C examples. It probably would be helpful if we:
  • Added a brief section in both the C and Objective-C articles about blocks and pointed to the main article
  • Expanded the main article Block (programming) to include C examples
I might be able to do this within in the next days (time permitting, of course), but you are welcome to attempt it! The Anonymouse (talk • contribs) 18:03, 26 November 2012 (UTC)

The new Objective-C feature called "block objects", in computer science terms, is not a Block (programming)... it's a Closure (computer science). "Block objects" are not part of standard C. From the Closure (computer science) article's section on Objective-C: Apple introduced Blocks, a form of closure, as a nonstandard extension into C, C++, Objective-C 2.0 and in Mac OS X 10.6 "Snow Leopard" and iOS 4.0.

So the question is... should "block objects" be discussed in the Objective-C article?

Tzadik (talk) 01:55, 27 November 2012 (UTC)

Blocks is a custom extension available for C, C++, and Objective-C, but C++ and Objective-C are really built on top of C, which is why I think that it's technically a C extension (not feature, as you pointed out, since it's nonstandard). Also, I think I got the wrong article – it's Blocks (C language extension). The Anonymouse (talk • contribs) 17:23, 27 November 2012 (UTC)
To actually answer your question: yes, I think a small section in the "Language variants" section (probably in the Objective-C 2.0 section), we should include some basic information, a small code example, and link to the main article:
The Anonymouse (talk • contribs) 17:27, 27 November 2012 (UTC)

Great! Thanks for calling my attention to Blocks (C language extension). I agree with what you said above.

Tzadik (talk) 17:47, 27 November 2012 (UTC)

plus Added The Anonymouse (talk • contribs) 08:07, 28 November 2012 (UTC)

Lack of formal language specification

Did anyone note that objective c is lacking a formal language specification? Until 2008 apple did include something like a syntax specification in their objective c spec, but i has since been scrapped. Itsme (talk) 21:53, 1 April 2013 (UTC)

Example Usage of Categories Could Be More Clear

I understand a little Objective-C and I'm trying to master categories. The code examples could be clearer. As I try to read them now, they say "integer, integer, integer, integer". Can somebody that understand categories and Objective-C well, rewrite these code examples to help those of us who have programming experience, but are trying to learn categories understand them better? — Preceding unsigned comment added by Kaydell (talkcontribs) 01:15, 25 August 2013 (UTC)

I agree, the examples could be more clear. Thea10 (talk) 01:25, 25 August 2013 (UTC)

Strict superset

From the Syntax section:

[Objective-C] is a strict superset of C; it is possible to compile any C program with an Objective-C compiler, and to freely include C code within an Objective-C class.
[Reference] "Write Objective-C Code". apple.com. 2013-04-23. Retrieved 2013-12-22.

First off, the notion of a "strict superset" is not defined here. Anyone well-versed in formal languages can tell you that there are at least two notions of superset that may be relevant: either all C programs are also Objective-C programs, or all C programs are also Objective-C programs with the same semantics. Given the emphasis in the text, I assume the latter is meant.

For that definition, this is not good enough a source. It states that

As a superset of the C programming language, Objective-C supports the same basic syntax as C

which (ignoring the apparently spurious word "basic") only talks about syntax, not semantics. This matter, because there are cases where e.g. C++ programs are also valid C programs, but with a different meaning, famously

#include <stdio.h>

int main()
{
    printf("%zu\n", sizeof('a'));
    return 0;
}

which is valid C89, valid C++98 and C++11, and outputs 1 in C++ but 4 in C (or 2 on a 286, or 8 on some supercomputers).

Finally, this source is an Apple website and Apple has an interest in selling Objective-C to C programmers, which is reason enough to doubt its reliability. I hope someone can come up with a better source for this, as this claim is made with the same source on C (programming language). QVVERTYVS (hm?) 16:23, 3 September 2014 (UTC)

Google will give you plenty of sources, e.g. [4]. "Strict" means that the semantics are the same. So it is an actual superset, not an approximate one like C++. --Frederico1234 (talk) 17:47, 3 September 2014 (UTC)
That source doesn't actually define "strict" either. This post to StackOverflow gives an example of a valid C module that doesn't even compile in Obj-C: void id() {}. QVVERTYVS (hm?) 12:20, 4 September 2014 (UTC)
id is typedef void. you can undef id. http://lists.apple.com/archives/objc-language/2004/Dec/msg00060.html
But there are still program that do not compile. You need to change some C programs to make them work, just like in C++. QVVERTYVS (hm?) 14:33, 4 September 2014 (UTC)
Restored the disputed template, and added {{verify credibility}} to the sources. All of them are selling Objective-C, and they only state that the language is superset of C, without proving or even arguing this. There is, apparently, no standard grammar of Objective-C (anymore?); there's cocoadev.com which states that "virtually all C-code compiles in an ObjC compiler" (emphasis added) and counterexamples can be found on various places on the internet. QVVERTYVS (hm?) 14:48, 4 September 2014 (UTC)
sources do not sell objc. cited statement supports stated statement. per you, "strict" is undefined, hence ignored.
Added some quotes to indicate that this is not a well-defined statement, as suggested by the previous poster. Sources are all somehow affiliated with Obj-C. QVVERTYVS (hm?) 15:31, 11 January 2015 (UTC)

license

What is the license of objective-c? Who owns the copyright? Daniel.Cardenas (talk) 07:04, 26 February 2016 (UTC)