Objective C is dominant programming language when we talk about iPhone applications development. Broadly speaking, objective C can be called a more refined form of its predecessors like C and C++, which can be considered the subsets of objective C. Objective C has a clear edge over C and C++ when it comes to efficient object-oriented interfaces. A clear advantage of objective C is that it can be implemented on top of existing C compilers rather than as a new compiler, since it contains almost all the features of C language. For the same reason, programming in Objective C requires at least some understanding of C.
Objective C is basically a blend of two languages: C and Smalltalk. If a person knows C (or even C++), programming in objective C is not much of a big task. Although the object declarations in C and objective C are same to quite a large extent, the methods (functions) differ to some extent. Consider this example for a function in C and objective C:
In C:
1 2 3 4 5 6 7 |
int sum (int r) { int count, result = 0; for (count = 0; count < foo; count++) result = result+ value(count); return result; } |
In Objective C:
1 2 3 4 5 6 7 |
int sum (int r) { int count, result = 0; for (count = 0; count < foo; count++) result = result + [value:count] return result; } |
Where value (int) is a method called in the above code. The most evident difference is the way a method is called. In C, we call a method within paraenthesis “()” while in Objective C, it is called within square brackets “[]”.
Two of the most distinguised and user-friendly features of objective C are proxies and categories, which are absent in C. These features help you in runtime binding and adding functionality to a library without recompiling. The advantage of this feature, coupled with the object oriented design provided by Objective C (as oppsed to structual desgin of C) is pretty evident when it comes to tackling large problems, since this provides the facility of diving a code into sub-codes or modules and develop and test each module independently. Same ease of coding is afforded with the help of classes, inheritance, protocols etc. which are absent in C but happen to be an integral feature of Objective C.