What is objective-C?

  • (2 Pages)
  • +
  • 1
  • 2

16 Replies - 8134 Views - Last Post: 01 September 2011 - 10:00 AM

#1 hulla  Icon User is offline

  • Writing Lines


Reputation: 49
  • View blog
  • Posts: 732
  • Joined: 05-March 11

What is objective-C?

Posted 06 August 2011 - 01:21 AM

What is objective-C and what is it used for? Thanks.
Is This A Good Question/Topic? 0
  • +

Replies To: What is objective-C?

#2 RudiVisser  Icon User is offline

  • .. does not guess solutions
  • member icon

Reputation: 1002
  • View blog
  • Posts: 3,562
  • Joined: 05-June 09

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.
Was This Post Helpful? 1
  • +
  • -

#3 hulla  Icon User is offline

  • Writing Lines


Reputation: 49
  • View blog
  • Posts: 732
  • Joined: 05-March 11

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?
Was This Post Helpful? 0
  • +
  • -

#4 RudiVisser  Icon User is offline

  • .. does not guess solutions
  • member icon

Reputation: 1002
  • View blog
  • Posts: 3,562
  • Joined: 05-June 09

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.
Was This Post Helpful? 1
  • +
  • -

#5 hulla  Icon User is offline

  • Writing Lines


Reputation: 49
  • View blog
  • Posts: 732
  • Joined: 05-March 11

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?
Was This Post Helpful? 0
  • +
  • -

#6 GWatt  Icon User is online

  • member icon

Reputation: 264
  • View blog
  • Posts: 3,059
  • Joined: 01-December 05

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.
Was This Post Helpful? 3
  • +
  • -

#7 hulla  Icon User is offline

  • Writing Lines


Reputation: 49
  • View blog
  • Posts: 732
  • Joined: 05-March 11

Re: What is objective-C?

Posted 06 August 2011 - 06:23 PM

Oh ok. Why does it use message stuff instead of function calls?
Was This Post Helpful? 0
  • +
  • -

#8 GWatt  Icon User is online

  • member icon

Reputation: 264
  • View blog
  • Posts: 3,059
  • Joined: 01-December 05

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.
Was This Post Helpful? 1
  • +
  • -

#9 heyoman1  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 64
  • View blog
  • Posts: 735
  • Joined: 30-November 09

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:
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

Was This Post Helpful? 4
  • +
  • -

#10 hulla  Icon User is offline

  • Writing Lines


Reputation: 49
  • View blog
  • Posts: 732
  • Joined: 05-March 11

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 . . . :(
Was This Post Helpful? 2
  • +
  • -

#11 GWatt  Icon User is online

  • member icon

Reputation: 264
  • View blog
  • Posts: 3,059
  • Joined: 01-December 05

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.
@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.
Was This Post Helpful? 1
  • +
  • -

#12 hulla  Icon User is offline

  • Writing Lines


Reputation: 49
  • View blog
  • Posts: 732
  • Joined: 05-March 11

Re: What is objective-C?

Posted 08 August 2011 - 07:48 AM

Quote

NS framework
What is NS?
Was This Post Helpful? 0
  • +
  • -

#13 GWatt  Icon User is online

  • member icon

Reputation: 264
  • View blog
  • Posts: 3,059
  • Joined: 01-December 05

Re: What is objective-C?

Posted 08 August 2011 - 08:24 AM

The NeXTStep framework from Apple.
Was This Post Helpful? 1
  • +
  • -

#14 heyoman1  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 64
  • View blog
  • Posts: 735
  • Joined: 30-November 09

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.
Was This Post Helpful? 1
  • +
  • -

#15 hulla  Icon User is offline

  • Writing Lines


Reputation: 49
  • View blog
  • Posts: 732
  • Joined: 05-March 11

Re: What is objective-C?

Posted 08 August 2011 - 10:29 PM

Oh ok . . . Thanks :)
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2