Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Essential points of Obj-C for the Pythonic crowd

 
Daren Wilson
Greenhorn
Posts: 16
Eclipse IDE Linux Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
author
Greenhorn
Posts: 22
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Bartender
Posts: 3479
Clojure Mac Objective C
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Never heard of Automatic Reference Counting in iOS 5 !! Wicked cool, thanks for mentioning it.
 
Fei Ng
Ranch Hand
Posts: 1244
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Greenhorn
Posts: 16
Eclipse IDE Linux Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Johannes, that is a great answer and helps me much with understanding the big picture about Obj-C! Thanks!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic