What are the differences between objective-C and C ++? Why does apple choose the former?

Source: Internet
Author: User

Zhihu: I have nothing to do with reading obj-C books in the library over the past few days. After reading obj-C for two days, I feel that this is not an object-oriented C, and the class syntax is so weird. What is the essential difference between this and C ++? Why does apple choose obj-C instead of C ++?

A: Objective-C is an extension of C. The design concept draws on the idea of Smalltalk's object-oriented and message mechanism. In my own object-oriented language, objc is the most thorough and explicit support for message transmission. The methods defined in the objective-C class are message passing, and the classes and messages are bound at runtime. during runtime, the compiler converts messages to the call of the objc_msgsend method. Other C ++, Java, Python, and Ruby are not obvious, but tend to encapsulate and abstract objects.

Objective-C and C ++ are basically two languages and do not have much to do with them. Objective-C is a static language. After compilation, It is a machine code with high execution efficiency. However, it introduces many dynamic features similar to Python and Ruby, such as dynamic type inference, ID, selector, block and other features, so it is very flexible. When you get used to Java or C ++, you will feel that the syntax of objective-C is very strange. But if you leave your mind blank and learn this language, you will soon fall in love with its messaging programming style, with xcode, both Mac and iOS apps are very handy.

To learn objective-C, you do not need to have a background in C. Instead, you can learn or review Objective-C. Since objective-C is a superset of C, therefore, execute C in the objective-C environment.ProgramNo problem.

Regarding why Apple adopts objective-C, it is not Apple adopts objective-C, instead, nextstep, the next operating system created by jobs, uses objective-C as the native language. Nextstep is based on Mach and BSD, and objective-C is its language and Runtime Library. Later, we all know that Apple bought nextstep and Steve Jobs returned to Apple, nextstep is also the basis of Max OS X. In the future, objective-C will become Apple's preferred language. Now, Apple is basically maintaining the development of this language.

Another point cannot be mentioned. The first web server was written on nextstep by Tim berneas-Lee, including a browser. So, we have to thank objective-C. Otherwise we still don't know what the Internet will look like ......

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.