Objective C vs C++

C has become one of the most popular programming languages in the world for several reasons, and it has been used as the base to develop many other programming languages. However, in the following article, we are not going to talk about why the C programming language family is so popular. We are going to talk about the differences and comparisons between Objective C and C++. These two programming languages are both derived from C, but they differ quite significantly from each other. Not sure about which to learn or use? Continue reading below!

Different Syntaxes
The most apparent difference is obviously the syntaxes of the two languages. C++ has inherited most of C’s syntax. Of course, there are several distinctions, and some C’s codes may behave differently in C++. However, the overall syntax is more similar to C and thus to many other C-based languages. The member function signature contains the function name and the types of the parameters and return. On the other hand, Objective C has a very different syntax. It utilizes a Smalltalk-like messaging paradigm that enables you to send messages to objects via methods or selectors. In Objective C, method parameters are allowed to be named. The method signature includes only the parameters’ names and types as well as the return type.

In C++, pointers are exist and should be managed well. You use “&” to specify the address of X. Meanwhile, in Objective C, pointers also exist but they don’t require you to think about them. Basically, you pass every object as a pointer, and when you input an object into a method, you are passing a pointer. But you only need to specify that it is a pointer to an object at the declaration.

Memory Management
A thing to point out: While both basically support object-oriented programming (OOP), C++ allows multiple inheritance. Objective C does not. Many programmers hate multiple inheritance.

One advantage of Objective C is the Automatic Reference Counting (ARC). This is a feature that counts the number of pointers to an object, and deletes it when the count goes to 0. This feature allows for automatic memory management. C++ does not have such automatic garbage collection. That is not necessarily a bad thing, but having the feature makes life easier.

Usage
Both C++ and Objective C are powerful general-purpose languages, but they are used in quite different fields. C++ is commonly used for coding Windows apps, e-mail clients, and operating systems. C++ has also been used to develop Apple’s Safari, Microsoft Visual Studio, and Java Virtual Machine. Meanwhile, Objective C is mainly used on Apple’s OS X and iOS operating systems as well as the respective APIs. Thus, some people consider that learning Objective C alone will restrict you to just OS X and iOS environments.

Objective CC++
- Distinctive syntax that utilizes Smalltalk-like messaging- The syntax is more similar to the C programming language
- Does not allow multiple inheritance- Allows multiple inheritance
- Has ARC- No automated garbage collection
- Used mainly in OS X and iOS environments- Used in operating systems and various apps

Conclusion
Even though Objective C and C++ are both derived from C, they are quite different from each other. They have very different syntaxes. C++ allows multiple inheritance, which many people consider as a bad thing. Objective C does not. In terms of memory management, Objective C is better than C++ due to the Automatic Reference Counting (ARC). Finally, C++ seems to be used in a wider range of applications, whereas Objective C is more restricted to OS X and iOS.

Leave a Reply