A comparison of C# and Objective-C - why I'm glad for MonoTouch

Written on

MonoTouch was released yesterday, which enables iPhone apps to be written in C#. This is a godsend for me personally, as I over the last few months I have been struggling to embrace Objective-C in the same way I have with C#. My own personal issues with the language are mainly the sheer amount of Objective-C code required for something I have come to expect as trivial in C#. A simple example can be demonstrated by a scenario where I might have a string representing a phone number that I want to strip of spaces and newline characters:

// phoneNumber = "\n   +44-7712-345-678    \n  \n"

// Objective-C code
NSString* newPhoneNumber =
[ [phoneNumber stringByReplacingOccurrencesOfString:@"\n" withString:@""]
stringByTrimmingCharactersInSet: [NSCharacterSet whitespaceCharacterSet] ];

// C# code
phoneNumber = phoneNumber.Replace("\n", "").Replace(" ", "");


My feeling is that programming languages should be elegant and concise. That's why things like the introduction of LINQ to C# interest me so much: instantly our ability to be expressive in our code has increased.

In his post about the MonoTouch release, Miguel de Icaza mentions that after porting the Objective-C sample apps to C#, there was half as much code. He points out that Objective-C developers are doing the same things over and over again: declaring the same variable 3 times (twice in the .h file, again in the .m file). I'm stunned the language hasn't evolved since the 1980's to remove those inefficiencies.

MonoTouch is giving me the opportunity to write apps for the iPhone in C#: a modern, evolving language. At the same time, it means I can avoid Objective-C, not because I'm scared of learning new technologies, but because I feel that it is old-fashioned, cumbersome and extremely hard to read.


Yup, I cannot agree with you anymore. Objective C is really old fashioned language. Apple choose Objective C for it's different though :p