Apple's new toy: Swift (Swift)-a large platter of popular programming languages

Source: Internet
Author: User

Swift is a new development language for Apple in this WWDC conference, and the developer's website has released the introduction, tutorials and manuals for the new language, and if you have an iOS device in hand, search for Swift from its official bookstore via Apple's ibooks app, An ebook version of its Official handbook can be downloaded.

Why is Apple launching a new language? Personal humble opinion, now the main development language of the Apple platform, Objective-c has been unable to evolve, can no longer develop, has been unable to catch up with the pace of modern programming language forward! Know objective-c history and principles of the people know, Objective-c is a shortcut to the language, it basically did not invent a new grammar, just the Smalltalk of the message interface mechanism on the C syntax, although it has both the C language efficiency and the ability to manipulate the system, Also has a dynamic language such as Perl, Ruby and other dynamic features, but its development has been limited to the old C syntax, and the C + + disgusting to vomit memory error, want to develop efficiency and rich expression ability to catch up with C #, go and other languages is impossible to complete the task, Therefore, the introduction of a new language from scratch, has not been a toss-up problem, but must be the thing.

Although Swift is a new language, it is not a re-invented language, but a hodgepodge of advanced languages! For example, many netizens first saw it use the Func keyword to define a function to say this is not the go language? Of course, it is not a simple clone of Go, as mentioned above, is a mix of the current popular language features (I personally think that Scala affects the most). I would like to cite a few simple examples, I think of the language source, I hope to see its design philosophy and language features. In advance, the limitations of personal knowledge, some sources may be inaccurate, but also please excuse me, thank you.

1. Declaring variables

Swift is a strongly typed language and introduces the type derivation mechanism of other strongly typed languages.
Declaring a variable

100

Declaring a constant

100

Variables and constants use different keywords, which should be modeled after Scala's Var and val,let keywords should be from Mozilla's rust language, but in the opposite sense.

2. Type declaration post
" Swift "

The source of this writing should be Pascal, and many popular strongly-typed dynamic languages now use this way to declare types, such as Scala.

3. All the functions are now closed.
Func getgasprices () (double, double, double) {  return (3.593.69  3.79)}

It's like the way Scala is written, it's about the same.

4. Class definition finally uses class

I just want to say, hehe.

5. Defining attributes Using Set/get
Double var perimeter:double {  get  {    return3.0 * sidelength  }   Set {    3.0  }}

This should be the grammar of the earliest invention of C #.

6. Overloaded parent method requires override keyword
override func simpledescription () String {  return'A Square with Sides of length \ (sidelength). " }

Should be a @override annotation from Java.

7.enum is a class definition

You can add a method to the enum, which I remember is Java, and c++11 introduced similar concepts and formulations.

8. Introduced (or reserved?) struct, which differs from class in that when a variable is assigned, a struct variable is a copy of the content, and the class is a reference to replication, which is undoubtedly something of C #. 9. Paradigm, you can create a method template
Func repeat<itemtype> (Item:itemtype, Times:int), itemtype[] {  = itemtype[] ()    for inch 0 .. Times {    + =  Item}  return  result}repeat ("knock  "4)

C + + played a lot of things for many years.

Of course, Swift also has a lot of things, here is just Dragonfly water casually enumerated a few, in general, functional programming, language dynamics, these programming language evolution of the trend, all in Swift, Swift also will Apple platform developers from the headache of memory errors, such as the bottom of the free, Focus more on the implementation of business logic.
However, from Objective-c to Swfit, the cost is still very high. Believe that the dynamic functional language enthusiasts, those accustomed to the use of Ruby,scala and other languages to develop the system of people, will like the new language, the current developers, especially those who are proficient in C + +, will have to spend more energy to convert thinking, after all, thinking inertia, not to say turn on the.

Finally spit the trough a bit, personally think through. And... The expression of the numerical space is very, very bad, see the following example you will know,

 for inch 0.. 3 // equivalent for (int i=0; i<3; i++) and the  for inch 0... 3 // equivalent for (int i=0; i<=3; i++)

Really do, hand shake a depressed function of the afternoon!

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.