File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes iOS and the fly likes Essential points of Obj-C for the Pythonic crowd Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Mobile » iOS
Bookmark "Essential points of Obj-C for the Pythonic crowd" Watch "Essential points of Obj-C for the Pythonic crowd" New topic

Essential points of Obj-C for the Pythonic crowd

Daren Wilson

Joined: Jun 29, 2008
Posts: 16

Most comparative overviews of Obj-C I've encountered so far have compared it to C, C++ and sometimes older language we don't see in the real world any more, like Pascal. I'm interested in comparing Obj-C to other popular languages that people I work with use.

How would you describe the main essential features, concepts, advantages of Objective-C to those with great experience in Python, who already understand OO, Python's way of doing things, and the slick tricks one can do in a dynamic language?

I have in mind people try to stay platform-independent, and mostly don't have any specific programming knowledge of OSX or iOS. But now some want to make a iPhone app, and are pondering whether to learn ObjC, use Java, or somehow do it in familiar comfortable Python.

Johannes Fahrenkrug

Joined: Mar 07, 2007
Posts: 22
Hi Daren,

great question. I've worked with Python a while ago and I really like the language. While I really like Objective-C, I by no means think that it's the One And Only True Language(tm) and that you should use it for everything. Always use the right tool for the job. For iOS development that happens to be Objective-C (at least primarily when you want to build native apps).

About the similarities:
- Both are object oriented, with classes and objects
- That's about it ;-)

The differences:
- Obj-C is C-based, you can mix and match Obj-C and C, even C++ and use lots of open source C-libraries in your Obj-C code
- Obj-C does not have namespaces (no packages). That kinda sucks, but in practice it's not as bad as it sounds.
- Obj-C is not a scripting language, it has to be compiled (which makes for very fast programs, but adds a compiler and linker step to your workflow)
- Obj-C uses square brackets. So calling "drawCircle" in Python is "foo.drawCircle(25, 50, 33)." In Obj-C: "[foo drawCircleAtX:25 y:50 radius:33]". Those named arguments make it a lot more readable, imho.
- Obj-C has "categories", which enable you to change existing classes (even of system libraries). I guess Python can do that, too.
- Obj-C has no significant whitespace
- Obj-C has no garbage collector on iOS. But a new addition for iOS 5 called "ARC" will mostly make manual memory management unnecessary
- Esp. string and array operations can be written in a much more concise way in Python than in Obj-C

This is probably not a complete list, but gives you an idea.

But in general this is my opinion: it takes time to learn the frameworks and the APIs, not so much the language. Even if Apple (or someone else) would support Python for iOS development one day, you'd still need to learn the CocoaTouch frameworks. So I'd say don't shy away from learning a new language, it's not that hard.

- Johannes
Hussein Baghdadi
clojure forum advocate

Joined: Nov 08, 2003
Posts: 3479

Never heard of Automatic Reference Counting in iOS 5 !! Wicked cool, thanks for mentioning it.
Fei Ng
Ranch Hand

Joined: Aug 26, 2000
Posts: 1242
John Todd wrote:Never heard of Automatic Reference Counting in iOS 5 !! Wicked cool, thanks for mentioning it.

Another cool thing about ARC is it has no performance hit, unlike other garbage collector. The compiler inserts retain/release into code for you and thats all it does.
Daren Wilson

Joined: Jun 29, 2008
Posts: 16

Johannes, that is a great answer and helps me much with understanding the big picture about Obj-C! Thanks!
I agree. Here's the link:
subject: Essential points of Obj-C for the Pythonic crowd
It's not a secret anymore!