Why Objective-c is difficult

Source: Internet
Author: User

Transferred from: http://mobile.51cto.com/hot-322261.htm 2012-03-07 13:43 junwong Open Source China communityfont Size:T | T

As a objective-c coder, I can always hear some people complaining about a lot of problems in this language. They're always trying to learn the language quickly to write an app, but they always think that objective-c seems too difficult or that these grammatical symbols are God's horse stuff? Yes, they asked very well, So I'll explain why many programmers are easy to learn from Ruby or Java, but hesitate when deciding to develop iOS or OS X apps.

AD: Dry Goods come, don't wait! WOT2015 Beijing Station lecture ppt open download!

Syntax :

First of all we talk about God horse is called programming language, programming language is a language that allows people to read and demonstrate the execution of the program, including the syntax (the correct expression and the use of State machine rules) and semantics (how to organize these expressions and state machine in a meaningful way to accomplish our goal)

Most programming languages are based on the C-syntax style, which is what we often call the dot syntax, depending on the decimal symbol to invoke the method or get the members of the class (of course, in C, the class is substituted for the struct). They are usually the definition of their own implementation class (note that Java is slightly different from C # and C + + in this case), but the specifics of these languages are the same anyway. When we come into contact with a new programming language, we are certainly happy to see that the grammar of the new language is familiar to us. After all, most programmers understand the syntax of the C language.

However, Objective-c is not a C-grammar-style programming language at all. It is so much different from the language syntax we are familiar with that most programmers simply do not understand that the OBJECTIVE-C code is God Horse.

Even some of the "strange" languages like Python or Ruby can be seen, after all, Python and Ruby are at least a bit grammatical style, using point syntax to invoke methods and get members of the class. On the contrary, their lack of branching structure does not affect the programmer's understanding for a long time, after all, the two languages have their own way of accomplishing the same goals.

Let's introduce the Objective-c language: Here I will compare it with another OOP language

I think there is no doubt that there is no problem here, to see this:

Well, I'm sure some of you want to ask a lot of questions. But that's not the worst of it, let's go on to see a tougher one:

General to here, I think we all have a few laps big head.

What is this, a god-horse situation? So many semicolons! And then there's a whole lot of questions coming up: How does this call the Divine Horse method? And how is it called? Is it performaction or something? How does the method overload work? Oh, my God!

It's best to forget about the method call we're familiar with. In fact, when you see performaction:withtwoparameters: We're actually talking about the message instead of the method. When you can understand this, the problem is much better.

In fact Objective-c is a very strict superset of C language. and the popular programming language style and the gap is too big. As a superset of the C language, it adds a lot of things and we'll simply see what complexity it adds.

Objective-c is a very "big" language, I mean its syntax is complex and flexible. Apple has minimized the size of the objective-c language, but they have added something 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 larger, the code used to express the same purpose is becoming more and more simple.

Run Time:

The OBJECTIVE-C runtime is dynamic, allowing you to add methods or remove methods and use reflection at run time for a class.

Unless you've used a language like Ruby or Lisp to support this feature, you'll feel weird. But please rest assured! When you try to use some good new features, it's very depressing at first.

Framework:

If you leave the Cocoa/cocoa touch frame, then objective-c can't create an app. Just as Ruby left rails, it couldn't create a Web application.

Cocoa is both big and old. For example, look at the Contentstretch property of UIView, the whole header file is something like this:

    1. @property (nonatomic) cgrect contentstretch __osx_available_starting (__MAC_NA,__IPHONE_3_0);
    2. //animatable. Default is unit rectangle {{0,0} { }}

That's all? First I assume it defines a stretched content area, but how does it work? Where are the rectangular cells? Cocoa/cocoa-touch is the only way to explain this, and as a newcomer to Objective-c, you can consult it.

History :

Vertically, Apple leads the development and maintenance of the Objective-c language, including Objective-c Runtime, Cocoa/cocoa-touch Framework, and objective-c language compilers. It looks like the objective-c is a cloud-like chart:

When you go to learn objective-c, it's not just a framework, a runtime or a compiler; Another important component is the Automatic Reference counting (the Dealloc method cannot be called directly after use), which makes it easier to use Cocoa/cocoa-touch programming.

Tightly coupled system code design is unique to objective-c. Other languages such as the. NET Framework to run Iron Python. And a whole bunch of non-Java languages running in the JVM, such as Clojure. Even Ruby and rails are two different projects. When you plan to use other languages with Cocoa/cocoa-touch and Objective-c runtime. Your only choice is Mac Ruby.

Future :

Over the past 4 years, we have seen that Apple has reduced the size and complexity of the objective-c language as much as possible. They also completed the manual memory auto-management and the classic C header file, and began to slowly introduce the attribute accessor to the point syntax and Automatic Reference counting to facilitate programmer programming. But for now, Objective-c is still more difficult to contact and learn, the only reason why it is becoming more and more popular is that it is the only way to do the iOS app.

"Editor: Cubic TEL: (010) 68476606"

Why Objective-c is difficult

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.