Syntax:
First, let's talk about Shenma's programming language. It is a language that allows people to understand and display the execution behavior of the program, including syntax (correct expressions and rules for using the state machine) and semantics (how to organize these expressions and state machines to accomplish our goals in a meaningful way)
Most programming languages are based on the C syntax style, that is, the dot syntax we often call methods or obtain class members by using decimal points (of course, in C, classes are replaced with struct ). They are generally self-implemented class definitions (note that Java is slightly different from C # And C ++ here), but the specifics of these languages are the same in any case. When we came into contact with a new programming language, we were certainly happy to see that the syntax of the new language was familiar to us. After all, most programmers understand the C language syntax.
However, Objective-C is not a C syntax-style programming language. It is so different from the familiar language syntax that most programmers simply cannot understand these Objective-C code.
Even some other "strange" languages like Python or Ruby can be seen. After all, Python and Ruby are at least syntactic, use the dot syntax to call methods and obtain class members. On the contrary, their lack of branch structures does not affect the programmer's understanding for a long time. After all, these two languages have their own ways to accomplish the same goal.
Next we will introduce Objective-C language: Here I will compare it with another OOP language.
I think we will certainly not have any problems here. Let's take a look at this:
Well, I think some people may want to ask a lot of questions. But this is not the worst. Let's look at a more powerful one:
This is generally the case. I think everyone has a few big circles.
Is this a real situation? So many semicolons! Terrible! Then there will be a lot of questions: Is this actually calling the Shenma method? How is it called? Is it about commit maction or something else? How to do this by using method overloading? Oh, my God!
We 'd better forget the method call we are familiar. In fact, when you see pull maction: withTwoParameters:, we are actually talking about messages rather than methods. It is much easier to understand the problem.
In fact, Objective-C is a strict superset of C language. The style is far behind that of popular programming languages. As a superset of C language, it adds many things. We will simply look at what complicated things it actually adds.
Objective-C is a very "big" language. I mean its syntax is complex and flexible. Apple has reduced the size of Objective-C language as much as possible. However, they have added some things to make Objecive-C expressions easier.
- Synthesizing properties
- Dot-syntax for accessing getters/setters
- Garbage Collection
- Blocks (closures)
- Automatic Reference Counting
- Weak references
So although the language is getting bigger and bigger, the code used to express the same purpose is getting simpler and simpler.
Runtime:
Objective-C is dynamic during runtime. It allows you to add methods or remove methods and use reflection for classes during runtime.
Unless you have used languages like Ruby or Lisp that support this feature, you will feel weird. But rest assured! It was depressing when you tried some good new features.
Framework:
If you leave the Cocoa/Cocoa Touch framework, Objective-C cannot create an App. Just as Ruby cannot create Web applications without Rails.
Cocoa is both big and old. For example, if you look at the contentStretch attribute of UIView, the entire header file is like this:
- @property(nonatomic) CGRect contentStretch __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_3_0);
- // animatable. default is unit rectangle {{0,0} {1,1}}
So much? First, I suppose it defines a content area that can be stretched, but how is this done? Where is the rectangle unit? Cocoa/Cocoa-Touch is the only way to explain this. As a newcomer to Objective-C, you can consult it.
History:
In the vertical view, Apple leads the development and maintenance of Objective-C language, including the Cocoa/Cocoa-Touch framework and the Objective-C language compiler during Objective-C runtime. It seems that Objective-C is like a cloud image:
When you learn Objective-C, it is not just a framework, a runtime or a compiler, but all of them. Another important component is the Automatic Reference Counting (the dealloc method cannot be called directly after use), which makes it easier for you to program using Cocoa/Cocoa-Touch.
Tightly coupled system code design is unique to Objective-C. Other languages such as Iron Python running under the. Net Framework. And a bunch of non-Java languages running on JVM, such as Clojure. Even Ruby and Rails are two different projects. When you plan to use other languages to work with Cocoa/Cocoa-Touch and Objective-C. Your only choice is Mac Ruby.
Future:
Over the past four years, we can see that Apple has reduced the size and complexity of Objective-C language as much as possible. They also completed manual memory Automatic management and classic C header files; and began to slowly introduce point syntax and Automatic Reference Counting for Attribute accessors to facilitate programming. However, it seems that Objective-C is still difficult to contact and learn. The only reason why Objective-C is becoming increasingly popular is that it is the only way to create iOS apps.