What is objective-C and what is it used for? Thanks.
16 Replies - 14466 Views - Last Post: 01 September 2011 - 10:00 AM
Replies To: What is objective-C?
#2
Re: What is objective-C?
Posted 06 August 2011 - 04:39 AM
A terrible language, for writing applications on OSX/iOS.
Of course it's still a language and yes it can be used anywhere, but you'll probably never see it outside of these platforms.
Of course it's still a language and yes it can be used anywhere, but you'll probably never see it outside of these platforms.
#3
Re: What is objective-C?
Posted 06 August 2011 - 06:11 AM
So there's a better replacement for objective-c? What does it do? Is it used for web design? OO programming? Versatile programming? Other?
#4
Re: What is objective-C?
Posted 06 August 2011 - 06:24 AM
A better replacement? Well yes of course!
It's a C-based language, the only "language" for web development is HTML/XHTML, design is just visualising.
It has a very strange non-OOP way of doing OOP which is definitely not OOP by any stretch of the matter. Also, you don't call functions, you send "messages" to them. It's God-awful.
It's a C-based language, the only "language" for web development is HTML/XHTML, design is just visualising.
It has a very strange non-OOP way of doing OOP which is definitely not OOP by any stretch of the matter. Also, you don't call functions, you send "messages" to them. It's God-awful.
#5
Re: What is objective-C?
Posted 06 August 2011 - 05:57 PM
Hahah... I thought that since it is called objective C, it would be OO in a user-friendly way. Send messages rather than call the function?! Horrible. . . Are there any things that it can achieve better than other languages which are helpful?
#6
Re: What is objective-C?
Posted 06 August 2011 - 06:07 PM
Objective C is an object oriented language that uses the smalltalk message passing syntax and semantics for classes and objects. The primary use of Objective C is currently for software development for Apple products. The Apple framework for Objective C is called NeXTStep. As far as I know, the only other modern Objective C framework is GnuStep, which aims to be compatible with NS. If you have access to a gcc compiler, chances are you can write Object C applications without much effort. One of the downsides of ObjC is that it's heavily dependent on a framework and, in my opinion, the NS framework just isn't very good.
#7
Re: What is objective-C?
Posted 06 August 2011 - 06:23 PM
Oh ok. Why does it use message stuff instead of function calls?
#8
Re: What is objective-C?
Posted 06 August 2011 - 11:13 PM
Using message passing instead of a function call allows for easier runtime binding. It also allows objects (also known as receivers) to forward the message to a different object/receiver. Also, message passing is how remote procedure calls work. I don't know if ObjC does this, but implementing an RPC that simply sends the selector and message across the network would probably work.
#9
Re: What is objective-C?
Posted 07 August 2011 - 11:33 AM
First off, Objective-C is not awful. It just does things differently. 
There are a few things that makes it appear different:
1) (Almost) Everything you make is a pointer. For example, when you want to make an instance of a class, it has to be a pointer. So for example, in C++ you would do:
While in Obj-C, you would do:
And that last part comes to number 2.
2) Messages are just methods in pointers.
C++ would do:
Obj-C would do:
This may look confusing, but this ties with #3.
3) Making methods. Obj-C uses some fancy syntax for making methods, but it makes it more readable.
C++ method in a class/outside a class:
Now Obj-C's:
4) Making classes
C++:
Obj-C:
5) #include -> #import
There is more, but that's the noticeable differences.

There are a few things that makes it appear different:
1) (Almost) Everything you make is a pointer. For example, when you want to make an instance of a class, it has to be a pointer. So for example, in C++ you would do:
MyClass *myclass = new MyClass();
While in Obj-C, you would do:
NSClass *myclass = [[NSClass alloc] init];
And that last part comes to number 2.
2) Messages are just methods in pointers.
C++ would do:
// from above myclass->someMethod(someVar, anothervar);
Obj-C would do:
[myclass someMethod: someVar AnotherVar: anotherVar];
This may look confusing, but this ties with #3.
3) Making methods. Obj-C uses some fancy syntax for making methods, but it makes it more readable.
C++ method in a class/outside a class:
// class void MyClass::someMethod(int var1, double var2); // outside a class someMethod(int var1, double var2);
Now Obj-C's:
// class + (void) someMethod: (int)var1 someVar: (double)var2; // outside class - (void) someMethod: (int)var1 someVar: (double)var2;
4) Making classes
C++:
class MyClass : public ParentClass { private: int somevar; protected: void someMethod(); public: char c; }; // in .cpp file void MyClass::someMethod() {}
Obj-C:
// if making a class, always subclass NSObject @interface MyClass : NSObject { // note you don't need the colon like C++, but you need a @ @public @private @protected // vars here } // method prototypes here @end // in the .m file @implementation MyClass // define methods here @end
5) #include -> #import
There is more, but that's the noticeable differences.
This post has been edited by heyoman1: 07 August 2011 - 02:08 PM
#10
Re: What is objective-C?
Posted 08 August 2011 - 06:19 AM
Oh ok. I usually like differences but . . . Looking at the source code . . . I'd rather consume frozen milk then learn that . . .

#11
Re: What is objective-C?
Posted 08 August 2011 - 07:45 AM
It's only syntax . . .
If it helps piques your interest something you can do in ObjC is auto-generate the get/set functions.
Demonstrated above is the default property/synthesize, which is to allow reading and writing. you can specify read/write only, as well as specifying how to pass objects instead of primitive data types.
Assign and copy are fairly simple to grasp. Retaining is how the NS framework handles memory management if you choose to not use the garbage collector. Each object has a reference count. Calling retain increments the reference counter, and release decrements the reference counter. So, telling the @property to use retain is simply an assignment with a call to retain.
Note, for property/synthesize to work you need to have Mac OS 10.5 or gcc 4.6 or higher.
If it helps piques your interest something you can do in ObjC is auto-generate the get/set functions.
@interface Fraction : Object { int numerator; int denominator; } @property int numerator @property int denominator @end
#import "Fraction.h" @implementation Fraction @synthesize numerator; @synthesize denominator; @end
Demonstrated above is the default property/synthesize, which is to allow reading and writing. you can specify read/write only, as well as specifying how to pass objects instead of primitive data types.
@property (readonly) int var; @property (writeonly) int var; @property (retain) Object *obj; @property (assign) Object *obj; @property (copy) Object *obj;
Assign and copy are fairly simple to grasp. Retaining is how the NS framework handles memory management if you choose to not use the garbage collector. Each object has a reference count. Calling retain increments the reference counter, and release decrements the reference counter. So, telling the @property to use retain is simply an assignment with a call to retain.
Note, for property/synthesize to work you need to have Mac OS 10.5 or gcc 4.6 or higher.
#12
Re: What is objective-C?
Posted 08 August 2011 - 07:48 AM
Quote
NS framework
#13
Re: What is objective-C?
Posted 08 August 2011 - 08:24 AM
The NeXTStep framework from Apple.
#14
Re: What is objective-C?
Posted 08 August 2011 - 02:54 PM
Actually, the NS means it's part of the Foundation framework. This is like Ruby.
It contains all these classes like Dictionaries, mutable arrays, data classes, etc that extend the power of Obj-C. You can use these and also extend them as part of Obj-C's categories feature, which allows you to override and make new methods for an already made class.
