This is an archive of past discussions. Do not edit the contents of this page. If you wish to start a new discussion or revive an old one, please do so on the current talk page. |
Archive 1 |
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 ( talk • contribs) 22:24, 18 October 2003 (UTC)
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)
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 ( talk • contribs) 05:36, 12 November 2004 (UTC)
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.
—The preceding unsigned comment was added by 64.81.33.177 ( talk • contribs) 07:14, 14 November 2004 (UTC)
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)
Being a newbie to Objective-C, but a big fan, I would offer the following opinion
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.
Apart from this, I think there are two main points about reusability, unrelated to what library you use...
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.
-- Iluvcapra 01:20, 4 Dec 2004 (UTC)
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)
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 ( talk• contribs) 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)
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)
- (int)changeColorWithRed:(int) r green: (int) g blue: (int) b ... [myColor changeColorWithRed:5 green:5 blue:5];
@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
@implementation Observer
- (retval_t) forward: (SEL) sel : (arglist_t) args
(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"];
if( boolean test ) statement ; else statement ;
@end
-- Keybounce 19:50, 16 May 2006 (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:
was suddenly changed to this:
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)
"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 ( talk • contribs) 21:39, 29 June 2005 (UTC)
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:
But the GNUstep user FAQ says the following:
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)
I am not sure, but is there 'try ... except'-like construction in Objective-C? —The preceding unsigned comment was added by Pdemb ( talk • contribs) 21:08, 6 January 2006 (UTC)
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 ( talk • contribs) 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)
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 ( talk • contribs) 08:24, 16 October 2006 (UTC)
I have just removed the following biased and unsupported statement from the article:
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)
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)
"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 ( talk • contribs) 07:57, 31 May 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)
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)
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)
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 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)
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)
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 ( talk • contribs) 07:46, 16 October 2006 (UTC)
Could someone who knows ObjC well enough provide a "programming language" infobox? —The preceding unsigned comment was added by 85.126.110.203 ( talk • contribs) 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 ( talk • contribs) 07:41, 16 October 2006 (UTC)
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 ( talk • contribs) 08:14, 16 October 2006 (UTC)
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 ( talk • contribs) 08:19, 16 October 2006 (UTC)
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 ( talk • contribs) 20:40, 16 October 2006 (UTC)
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. — lensovet– talk – 02:16, 25 January 2007 (UTC)
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)
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
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)
"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)
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)
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"?
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 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)
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.
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 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)
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)
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)
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)
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)
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 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)
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)
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)
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)
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)
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)
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)
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 ( talk • contribs) 20:16, 23 July 2012 (UTC)
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
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)
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)
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)
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)
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)
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 ( talk • contribs) 01:15, 25 August 2013 (UTC)
From the Syntax section:
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
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)
void id() {}
.
QVVERTYVS (
hm?) 12:20, 4 September 2014 (UTC)What is the license of objective-c? Who owns the copyright? Daniel.Cardenas ( talk) 07:04, 26 February 2016 (UTC)
This is an archive of past discussions. Do not edit the contents of this page. If you wish to start a new discussion or revive an old one, please do so on the current talk page. |
Archive 1 |
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 ( talk • contribs) 22:24, 18 October 2003 (UTC)
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)
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 ( talk • contribs) 05:36, 12 November 2004 (UTC)
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.
—The preceding unsigned comment was added by 64.81.33.177 ( talk • contribs) 07:14, 14 November 2004 (UTC)
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)
Being a newbie to Objective-C, but a big fan, I would offer the following opinion
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.
Apart from this, I think there are two main points about reusability, unrelated to what library you use...
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.
-- Iluvcapra 01:20, 4 Dec 2004 (UTC)
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)
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 ( talk• contribs) 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)
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)
- (int)changeColorWithRed:(int) r green: (int) g blue: (int) b ... [myColor changeColorWithRed:5 green:5 blue:5];
@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
@implementation Observer
- (retval_t) forward: (SEL) sel : (arglist_t) args
(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"];
if( boolean test ) statement ; else statement ;
@end
-- Keybounce 19:50, 16 May 2006 (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:
was suddenly changed to this:
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)
"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 ( talk • contribs) 21:39, 29 June 2005 (UTC)
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:
But the GNUstep user FAQ says the following:
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)
I am not sure, but is there 'try ... except'-like construction in Objective-C? —The preceding unsigned comment was added by Pdemb ( talk • contribs) 21:08, 6 January 2006 (UTC)
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 ( talk • contribs) 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)
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 ( talk • contribs) 08:24, 16 October 2006 (UTC)
I have just removed the following biased and unsupported statement from the article:
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)
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)
"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 ( talk • contribs) 07:57, 31 May 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)
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)
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)
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 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)
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)
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 ( talk • contribs) 07:46, 16 October 2006 (UTC)
Could someone who knows ObjC well enough provide a "programming language" infobox? —The preceding unsigned comment was added by 85.126.110.203 ( talk • contribs) 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 ( talk • contribs) 07:41, 16 October 2006 (UTC)
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 ( talk • contribs) 08:14, 16 October 2006 (UTC)
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 ( talk • contribs) 08:19, 16 October 2006 (UTC)
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 ( talk • contribs) 20:40, 16 October 2006 (UTC)
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. — lensovet– talk – 02:16, 25 January 2007 (UTC)
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)
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
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)
"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)
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)
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"?
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 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)
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.
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 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)
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)
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)
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)
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)
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 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)
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)
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)
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)
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)
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)
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)
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 ( talk • contribs) 20:16, 23 July 2012 (UTC)
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
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)
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)
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)
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)
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)
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 ( talk • contribs) 01:15, 25 August 2013 (UTC)
From the Syntax section:
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
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)
void id() {}
.
QVVERTYVS (
hm?) 12:20, 4 September 2014 (UTC)What is the license of objective-c? Who owns the copyright? Daniel.Cardenas ( talk) 07:04, 26 February 2016 (UTC)