grammar
Let's talk about what a programming language is. The so-called programming language is a kind of program code that people can read. A programming language usually contains a series of contents: grammar (the rules of statement writing and declaration) and semantics (to achieve certain tasks and effectively combine statements and declarations).
Most (usually) programming languages are similar to C language in method calls, and members of access classes adopt. Grammar. (that is, the structure in c). Although these languages generally have their own ways of defining classes (Java is quite different from C# or C++), many details of the languages are very similar. Whenever people come into contact with a new programming language, if its grammar looks familiar, it will make learners feel very comfortable. Like most people have a background in C grammar, so if you want to learn a language with C grammar, your first impression will be very cordial.
From the perspective of grammar alone, Objective-C is unique. Its grammar is so special that many people have no patience to delve into its semantics, just like C++, Java and other languages.
So-called "strange" languages such as Python and Ruby are easier to use because they can be accessed through. Grammar. And people can usually get used to indenting rather than curly braces quickly.
When I introduce Objective-C to others, generally speaking, I will compare it with an OOP (object-oriented programming) language.
Why is objective-c difficult to learn 1
So far, not bad. Maybe they knew lisp before, so it is not difficult to understand this grammar.
Why objective-c is difficult to learn 2
This sentence is generally unacceptable and the situation has become less optimistic.
Why objective-c is difficult to learn 3
This sentence can directly make people collapse.
What are those colons? It's so scary! Then a bunch of questions came up: what's the method? Is it through performance or other means? How to overload a method?
You know, we're not talking about methods, we're talking about messages (I won't discuss the differences between them) and selectors, just like the above-mentioned performation: there are two parameters. However, everyone is too lazy to understand.
Objective-C is a superset of C. It is actually a very cool programming language, but because of its own characteristics, compared with other modern programming languages, people will think that Objective-C is very old. As a superset of C, Objectivec-C extends a series of unconventional features on the basis of C, but only increases the complexity of Objective-C.
Objective-C is a large language. The starting point of this definition is that its grammar is very complicated. In fact, Apple has been making great efforts to slim down Objective-C. For example, although it is very slow, it has finally completed the transition from the original document to the standard C style. Moreover, Apple has made many improvements to Objective-C and added many new functions to make the code of Objective-C more concise, such as:
over-all properties
By accessing getter/setter. Grammar.
Garbage collection (garbage collection)
Block (closed)
Automatic reference counting
Weak citation (weak citation)
Therefore, although the language has become more and more huge, the complexity of developing and writing code has decreased.
run time
The dynamic operation of Objective-C may not be so intuitive just from the origin of C, because there is no need to write assembly code directly, so C language itself is a low-change language. Since Objective-C is a superset of C, it is easy for us to be inclined to the stability of Objective-C, but in fact Objective-C is a dynamic and flexible language. Objective-C supports the function currying and reflection mechanism, and can dynamically add or delete methods of classes at runtime.
Unless you have been exposed to programming languages with characteristics similar to Objectivec-C, such as Ruby or Lisp, it is difficult to adapt to Objectivec for the time being. But don't worry! Some things, seemingly mysterious and terrible, are actually not that complicated in nature.
structure
Using Objective-C to build an app is completely inseparable from the Cocoa/Cocoa Touch framework. Just as developing web applications with Ruby is inseparable from Rails.
After years of development, cocoa has become very heavy. However, as mentioned above, Apple is gradually losing weight for the Cocoa Touch framework on which conventional iOS development depends to reduce its complexity. Even so, even if the app to be developed is extremely simple, there are still many things to learn. For example, Apple's official documents and various exposed header files are good learning resources. Take the contentStretch property in UIView as an example. The header file is defined and described as follows:
@ property (nonatomic) cgrect content stretch _ _ OS x _ available _ starting (__MAC_NA, _ _ iPhone _ 3 _ 0);
//Animation can be made. The default is the unit rectangle {{0,0} {1,1}}
What the hell does this mean? According to my understanding, this attribute is used to describe the size of the extensible region. But how to achieve it? Does this area refer to a rectangle? Maybe you will never deal with this attribute, but if you use this attribute at some time and in a certain scene during the development process, you can easily solve your problem. Will you know it exists and use it correctly at that time?
Cocoa/Cocoa-Touch is a huge framework. To really master it, practice makes perfect. But this familiar process often makes many novices flinch.
history
For a long time, Apple has been promoting the development system of Objective-C language. The overlapping of a series of higher-level designs, such as Objective-C runtime, Cocoa/Cocoa Touch framework and Objective-C compiler, makes Objective-C more than just a language.
Why objective-c is difficult to learn 4
Therefore, when learning Objective-C, we should not learn languages, frameworks, their operating mechanisms or compilers in isolation, but integrate them. For example, the ARC (Automatic Reference Counting) mechanism integrated by Objective-C now involves the semantic layer (no need to display and call dealloc), the compiler layer (obviously) and the naming convention of Cocoa/Cocoa Touch framework.
The design closely related to some columns of Objective-C mentioned above is its uniqueness. Other languages will depend on other languages or platforms to run more or less, such as Iron Python based on. Net, Clojure, which is not Java but depends on JVM, even Ruby and Rails actually have their own relatively independent entities and projects. The only well-known Mac Ruby supported by Cocoa/Cocoa Touch and Objective-C runtime was later stopped by Apple and subsequently supported.
Objective-C and related frameworks, runtimes, compilers, etc. are almost closed to other developer communities.
future
Judging from the information currently available, Apple has been trying to reduce the complexity of the Objective-C language for the past four years. Manual memory management and C standard header file are cancelled, and ARC mechanism which is more in line with the current programming language trend is introduced, and properties are accessed through getter/setter method. Grammar is to reduce the learning cost of Objective-C, but even so, Objective-C is still a development language with a certain learning threshold, and its popularity is entirely brought by the popular iOS application based on Objective-C.