What can a C# developer learn from Objective-C? [closed]
What aspects of Objective-C do you like and why (specially comparing with C#)? Has C# lost something on the way comparing to older languages as C, C++ and Objective-C
1. Memory Management
I'd say one of the biggest benefits is the explicit memory management that Obj-C requires. At least, there is a garbage collector but you have to opt-in knowingly. I can't tell you how much thread deadlock and memory leakage I had with C# because I expected the GC to do my work for me. What it taught me was to make pretty much all classes in C# implement IDisposable
. No object should ever assume that mommy will clean his room for him.
2. Message Sending
Rather than the concept of a "method", "messaging" seems much more realistic to me. You send an object a message, telling it what to do. It's mainly semantics, but it can make all the difference in how you design classes.
3. Message Syntax
Some consider the verbose style of obj-c messages to be a downside, but I personally like it. I can look at a line of code, and instantly know what all the parameters are for, without having to consult metadata. It's almost like Ruby in the sentence-like construction, just not as succinct. For example, seeing if one class is a subclass of another is quite readable to strangers:
[animal isSubclassOfClass:organism]
In addition, this verbose syntax starts to make you really think about how your program should be designed in order to minimize the amount of cruft that builds up. I feel that my classes in objective-C are much smaller and more purposeful than in C#. It's not easy to build giant super-classes full of methods. So, it promotes good design.
4. Deployment
When jobs exist for a technology that are primarily for deploying software, there is a problem. As a developer, I should be able to cleanly package something with the click of a button, and have it ready for consumption by my clients. C# is a nightmare, and while much of that has to do with the way Windows is built as opposed to OSX, they could learn a lot from Apple. Packaging with XCode is a breeze. It's not a language feature, but it makes all the difference when it comes time to actually deploying what you've written. Spend your time coding good software, not making installers.
5. Interface Builder
Again, this isn't really a language feature as much as an IDE feature, but it should be included. Interface Builder promotes MVC from top to bottom. Presentation logic is 100% separate from controller or model logic by design. Plus, it's just dead easy to use.
Objective C is a pure superset of ANSI C. Thus you can port and reuse a huge amount of C library code, emulators, numerical libraries, etc. written for Linux/Unix.
Objective C is also unmanaged, so you can access and optimize the bits in memory to your hearts content, which is useful if you are trying to minimize every byte and battery-eating processor cycle. Memory management is also explicit, which allows a competent programmer to minimize memory usage without wasting processor cycles to do it less efficiently via garbage collection. Basically, you can learn how to develop code that is can offer much better battery life on tiny portable devices.
If you know and like C# just goto Mono for the Iphone (http://monotouch.net/).
精彩评论