I am a newbie to Mac. I have seen people saying that learning a new programming language each year is worthy to enrich programming skills .As a beginner to the IT field I feel interesting to explore new things . I would like to share the knowledge I am gaining in finding out the difference between C#.NET and Objective C Programming languages through my blogs so that this will be helpful for any one moving from C# to Objective C.
A direct comparison of both the language seams to be awkward as both are built to use different platform, different frame work, different development environment. Objective C uses Cocoa and Cocoa touch frameworks where as C# language is built to use .NET frame work. Both are rich frameworks in their own purpose and rights as Cocoa and Cocoa touch targets the Mac OS X & iPhone,iPad respectively and .NET obviously the Windows. Similar case with the IDE also, Xcode is the common IDE used for developing Mac application. And Visual studio the usual IDE used for coding C#.NET.
To begin with syntactically Objective C which is advanced form of C by adding object orientation to it. Where as C# I would say derived from C++ and JAVA. The major difference in both these language comes in fact that C# has a dot notation to access methods. Objective C talks within objects by passing messages. C# releases the head ache of separating the declaration from implementation of classes and methods when compared to Objective C. Unlike C#, in Objective C the classes and methods are declared at one end and implemented at other end. I would like to introduce the way how Objective C differs syntactically for declaring class and methods.
For any xcode project using objective C two files are created by default one in where the declaration is done called .h file and .m where the implementation take place.To declare and implement a class and a method in C#
public class addition
public void add(int a,int b)
//codes for operation....
where as in Objective C the code is
//codes for operation......
@interface is the keyword used to declare a class and not similar to interface in c# .If you are looking for the interface equivalent of C# in Objective C then it is '@protocol' in Objective C. Any class started must end with an '@end' as shown above. The function 'add' is declared in the class with two parameters separated by the colon . The implementation is done in .m file .
To call a function in C# we go for
addition addobject = new addition();
This could be accomplished in Objective C through the following codes
addition *addobject = [[addition alloc]init];
Another interesting thing that I noticed was the string syntax in objective C and C#. I have used regular expression in C#.NET where I used @ symbol with strings in double quotes to denote quoted string literals. Where as in Objective C it denote the CoreFoundation string .
Another major fact for any person new to Objective C is the memory management. C# provides automatic garbage collection and these has to be done manually in IOS. (ie) every call to alloc should be matched with end of current scope.I would also like to explain the concept of memory management in my up coming blogs..