This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
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.
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 ;-)
- 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.