views:

69

answers:

1

I have heard it said that Objective c is a 'simple' language, i.e. in terms of it's language features. It's really the only language that I know but I did a bit of Java before and, in terms of language features, they seem to be pretty close.

I have never touched C++. Is there more features to C++ compared with Objective-C and if so, is it an advantage to work with this extra feature set?

+5  A: 

I've never heard of Objective-C described as a 'simple language'; on the contrary, some of the language features of Objective-C – such as dynamic binding, categories and introspection – make it a rather powerful language.

However there are a few reasons why it could be seen to be a language that is less feature-rich than others, including:

  • There was no garbage collection (generally speaking) until Apple's Objective-C 2.0, before which memory was managed largely by reference-counting; this is different to languages such as Java which use garbage collection for all memory management.
  • There are no namespaces in Objective-C; again this is unlike other languages out there such as C++. Convention is that classes and functions should be prefixed, as can be seen in Foundation, AppKit etc which are prefixed with NS-. This can sometimes be a disadvantage.
  • There are no true abstract classes. In Objective-C, abstract classes are only abstract by design, and can still be instantiated as-is, and won't generate compiler warnings or errors.
  • There is no operator-overloading. This is due to the nature of the Objective-C runtime and how method dispatch works. Instead, methods that take different argument types must be named differently; this may not necessarily be a disadvantage, as it can often improve clarity of code.

However despite all of this, Objective-C has some rather useful features, some of which are directly or indirectly the result of the lack of certain features that other languages may have, such as:

  • Using descriptive names (due to no operator overloading) often clarifies code and allows it to be self-documenting in many circumstances.
  • Categories are useful for extending classes that you do not have direct access to.
  • Dynamic dispatch means you can add, change or remove methods at will, and provides powerful introspection of classes.
Perspx
many thanks for this. I will read up on some of those points. I agree that the convention of long method names is useful in how self documenting it can be. at first it looks awkward but then you get into the 'parseNamesInDictionaryAndPutInOtherDictionary' vibe.
Remover