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 ......