This is a mirror of official site: http://jasper-net.blogspot.com/

The Objective-C Language from a Java / C++ perspective

| Thursday, May 6, 2010
If you are a Java, C#, or C++ developer, then you are probably not excited to learn Objective-C.   Objective-C code is hard to read, and I sometimes wonder why Apple would chose an “ancient” language as a basis for a brand new mobile platform? The language is about to turn 25 years old.

I really wanted to write some iPhone applications, so I started learning about Objective-C a few months ago. Once I got past the unusual syntax and unfamiliar Xcode tools, I realized that this language has a lot to offer object oriented developers. I’d like to share with you my favorite Objective-C language features.

First off, Objective-C is very different from C++. What a relief!   C++ is not my favorite language. I spent years learning the intricacies of C++.  It’s a very difficult language to learn, it’s way too complex for most developers. I’m so glad Objective-C is a simpler, and far more powerful language than C++. Read on for some details…

Powerful Objective-C language features:

   * Dynamic Messaging Passing
         o Objects pass messages, rather than make direct method calls.  It seems like a subtle distinction, but message passing is very flexible.  Object messages can be auto-forwarded, passed over a network, or even queued up and sent at a later time. Dynamic message dispatch enables many of the important object oriented features in the language.
         o Nil (or null) pointer protection is built in. Sending a message to nil (null) will cause a C, C++, or Java program to crash.  In Objective-C, the message simply gets dispatched to … nowhere! Nothing bad happens, and the program continues to run. (Debug code can be added to detect messages being sent to Nil.)

   * The compiler is Type-safe, and the runtime provides super easy object introspection
         o For the most part, Objective-C is strongly typed. The compiler catches most type related errors. I prefer typed languages, because I want to catch my simple mistakes before I run the application.
         o At runtime, object type information is fully available.  It’s easy to check the type of an object and find out which messages (methods) it accepts. It’s basically a single line of code to access type information, compared to Java which requires 4 or 5 lines of code to do the same type lookups.

Read more: Gavin Pierce on Software

Posted via email from jasper22's posterous

0 comments: