Apple's top secret Swift language grew from work to sustain Objective C, which it now aims...

Posted:
in Mac Software edited December 2019
Work on Swift--Apple's surprise new programming language unveiled at WWDC--started development four years ago in conjunction with efforts to keep Objective C relevant. Swift now aims to quickly replace Objective C for modern Cocoa development on iOS and OS X.

LLVM


Rather than being an entirely new "beta" idea, work on Swift started in the summer of 2010, according to the new language's originator Chris Lattner (below), who has worked at Apple since 2005. Lattner is probably best known for LLVM, the Low Level Virtual Machine compiler infrastructure project with a wyvern dragon mascot (above).

LLVM: A new compiler for Objective C

LLVM originated as Lattner's research project while a student at the University of Illinois, Urbana-Champaign in 2000. It was first publicly released as version 1.0 in 2003. In 2004, Lattner was a summer intern at Microsoft Research, where he worked on the Phoenix complier infrastructure, working to allow LLVM to compile and run .NET code.

Chris Lattner


Lattner caught the attention of Apple after posting questions about Objective-C to the company's objc-language mailing list. Apple in turn began contributing to Lattner's LLVM open source project in 2005 and subsequently hired Lattner and began funding his work.

In 2007, the LLVM project released Clang, a front end code parser for Objective C/C/C++ aimed to provide fast compiling with low memory use, expressive diagnostics, a modular library-based architecture, and tight integration within an IDE such as Apple's Xcode.

In addition to the "pure" LLVM Clang project, Lattner also proposed integrating the new LLVM, featuring its advanced code optimizer and code generator, into the existing GCC (GNU C Compiler), adding modern methods for "aggressive loop, standard scalar, and interprocedural optimizations and interprocedural analyses" missing in the standard GCC components that had long been a core element of the development tools in Unix operating systems like Apple's OS X.

GCC's support for Objective C, the primary development language of Apple's OS X Cocoa (and NeXTStep, its historical predecessor), had grown stagnant, so Apple's motivation for funding the open development of both Clang and LLVM-GCC involved keeping the Mac's Objective C relevant as a language.

Apple began aggressively using LLVM in OS X, providing LLVM-GCC to its Mac developers in order to provide access to the new LLVM compiler and benefit from its code optimizations without requiring substantial changes to their workflow based on the previous GCC.

The company also integrated LLVM into the OpenGL stack of OS X 10.5 Leopard in 2006, and leveraged LLVM to help in migrating the Mac to Intel beginning in 2005 and to the ARM architecture for the iPhone in 2007.

By the 2012 release of OS X Mountain Lion and iOS 6, Apple had moved entirely to Clang, leaving both LLVM-GCC and GCC behind. LLVM not only powers Apple's software, but is also tightly integrated into the development of Apple's custom silicon, including the A6 and A7 Application Processors.

LLVM also plays a key role in other Apple technologies, from the LLDB debugger to new APIs including Metal, Apple's new layer for high performance graphics on iOS that exposes the graphics capabilities of the newest A7 with the least possible overhead, delivering a significant performance boost over using the more general purpose OpenGL.

Swift: A new language for LLVM

By 2010, LLVM's solution to GCC's stagnant Objective C support created a new scenario where LLVM could now support more features than could be easily added to Objective C. Lattner began working on a new programming language that summer, and a year later was joined by "a few other (amazing) people."

By July 2013, Lattner noted that the new Swift project had become "major focus for the Apple Developer Tools group." It remained a secret to the public for the next year. Lattner notes in his resume that he "took over management and leadership of the entire Developer Tools department at Apple" at the beginning of 2013.

"In addition to compilers and low-level tools," Lattner notes, "I am now responsible for the Xcode IDE, Instruments performance analysis tool, Apple Java releases, and a variety of internal tools. Xcode 5 is the first result of this work, though much of the feature planning and implementation was complete before I took over. I drove convergence and defined a few key features that were released at WWDC."

Lattner noted that the new Swift language "is the product of tireless effort from a team of language experts, documentation gurus, compiler optimization ninjas, and an incredibly important internal dogfooding group who provided feedback to help refine and battle-test ideas. Of course, it also greatly benefited from the experiences hard-won by many other languages in the field, drawing ideas from Objective-C, Rust, Haskell, Ruby, Python, C#, CLU, and far too many others to list."

Apple's free iBook on Swift also notes that "Swift has been years in the making," adding that "Apple laid the foundation for Swift by advancing our existing compiler, debugger, and framework infrastructure.

"We simplified memory management with Automatic Reference Counting (ARC). Our framework stack, built on the solid base of Foundation and Cocoa, has been modernized and standardized throughout. Objective-C itself has evolved to support blocks, collection literals, and modules, enabling framework adoption of modern language technologies without disruption. Thanks to this groundwork, we can now introduce a new language for the future of Apple software development.""Swift is the first industrial-quality systems programming language that is as expressive and enjoyable as a scripting language"

The company also observes that Swift "is friendly to new programmers. It is the first industrial-quality systems programming language that is as expressive and enjoyable as a scripting language."

Apple also draws attention to the integration between Swift and LLVM, noting that the new language "combines the best in modern language thinking with wisdom from the wider Apple engineering culture. The compiler is optimized for performance, and the language is optimized for development, without compromising on either."

Swift's Interactive Playgrounds & REPL

Lattner also commented on two new features associated with Swift: Xcode's new Playgrounds (below) and REPL (Read-Eval-Print-Loop) debugging console.



"The Xcode Playgrounds feature and REPL were a personal passion of mine, to make programming more interactive and approachable," Lattner noted. "The Xcode and LLDB teams have done a phenomenal job turning crazy ideas into something truly great.

"Playgrounds were heavily influenced by Bret Victor's ideas [which are cited as a inspiration for Khan Academy's online environment for learning to program], by Light Table [an open source IDE designed to provide realtime feedback about code and how programs work] and by many other interactive systems.

"I hope that by making programming more approachable and fun, we'll appeal to the next generation of programmers and to help redefine how Computer Science is taught," Lattner stated.

Apple's presentation of Swift notes that "Playgrounds make writing Swift code incredibly simple and fun. Type a line of code and the result appears immediately. If your code runs over time, for instance through a loop, you can watch its progress in the timeline assistant. The timeline displays variables in a graph, draws each step when composing a view, and can play an animated SpriteKit scene. When you've perfected your code in the playground, simply move that code into your project."

The company states that Xcode's Playground lets users "design a new algorithm, watching its results every step of the way; create new tests, verifying they work before promoting into your test suite; experiment with new APIs to hone your Swift coding skills."

Apple notes that the REPL debugging console in Xcode "includes an interactive version of the Swift language built right in. Use Swift syntax to evaluate and interact with your running app, or write new code to see how it works in a script-like environment."

Apple says it plans to rapidly evolve Swift in response to developers needs and feature requests.

Thinkful, an education startup focused on mentor-led programming education, has already announced plans to offer a course on developing in Swift, in a program that begins July 16.
«1345

Comments

  • Reply 1 of 93
    macinthe408macinthe408 Posts: 1,050member
    I love reading this stuff, even though I understood only three words in the entire article.
  • Reply 2 of 93
    malaxmalax Posts: 1,598member

    I hope Christian Laettner has a long-tenured career at Apple.  He's clearly been doing great things since leaving Duke.  Just kidding with the lame basketball reference, but guys like this will help Apple stay great.  Thanks for the interesting article.

  • Reply 3 of 93
    tallest skiltallest skil Posts: 43,388member

    Let’s muse:

    Will Swift really be able to supplant Objective-C?

     

    Also, Isn’t Peregrine a better name for it, given the icon? :p Then we could even shorten it to “P”, eventually having P++. ;) 

  • Reply 4 of 93
    adhiradhir Posts: 50member
    This might be the single most important advancement presented at this year's WWDC.
  • Reply 5 of 93
    dugbugdugbug Posts: 283member
    apple are so gung-ho on potential swift language development they said they cannot promise source compatibility with the language itself during the beta(though they will promise binary compatibility). Dang.
  • Reply 6 of 93
    mjtomlinmjtomlin Posts: 2,673member
    Quote:
    Originally Posted by Tallest Skil View Post

     

    Let’s muse:

    Will Swift really be able to supplant Objective-C?

     

    Also, Isn’t Peregrine a better name for it, given the icon? :p Then we could even shorten it to “P”, eventually having P++. ;) 


     

    I don't know... Here's a swift.

     

    and another

  • Reply 7 of 93
    chandra69chandra69 Posts: 638member
    I hope no other company would snatch this guy away from Apple.
    These kind of stories about great engineers and their work really inspire a lot.
  • Reply 8 of 93
    mjtomlinmjtomlin Posts: 2,673member
    Quote:
    Originally Posted by macinthe408 View Post



    I love reading this stuff, even though I understood only three words in the entire article.

     

    I've read half way through the Reference Manual already... Lots of good stuff. I really like the removal of a lot of the baggage that came along with Objective-C in order to extend the Standard C syntax - although Apple has been hard at work at removing much of it over the passed few Xcode releases.

     

    Xcode 4:  

    NSArray *names = [[NSArray alloc] initWithObjects: @"Tom", @"Dick", @"Harry", nil];

     

    Xcode 5:

    NSArray *names = @[@"Tom", @"Dick", @"Harry"];

     

    Swift:

    let names = ["Tom", "Dick", "Harry"]

     

     

     

    Side note: Anyone remember Dylan? Another language developed by Apple in the early 90's.

  • Reply 9 of 93
    chandra69chandra69 Posts: 638member
    Quote:

    Originally Posted by mjtomlin View Post

     

     

    I've read half way through the Reference Manual already... 


    I only finished a little.  I felt like ... it is scripting language and awesome. How do you guys find time? ;)

  • Reply 10 of 93
    cykzcykz Posts: 81member
    Like macinthe408 I hardly understood and love reading the article. I second adhir's comment. Advancing development with better language, better tooling and upscaling the level of abstraction to the degree that we can focus on creating something new while automating performance management is key to outperform the competition. As a developer and as company.
  • Reply 11 of 93
    phone-ui-guyphone-ui-guy Posts: 1,019member
    Quote:
    Originally Posted by Tallest Skil View Post

     

    Let’s muse:

    Will Swift really be able to supplant Objective-C?

     

    Also, Isn’t Peregrine a better name for it, given the icon? :p Then we could even shorten it to “P”, eventually having P++. ;) 


     

    Have you not seen a swift in flight?

     

     

     

     

    Also, "Peregrine" isn't also a pun for it being really fast.

  • Reply 12 of 93
    solipsismxsolipsismx Posts: 19,566member
    Also, Isn’t Peregrine a better name for it, given the icon?

    I like the name but I recommend changing the icon to this…
  • Reply 13 of 93
    solipsismxsolipsismx Posts: 19,566member
    Also, "Peregrine" isn't also a pun for it being really fast.

    It's also too close to the word perineum. :p
  • Reply 14 of 93
    suddenly newtonsuddenly newton Posts: 13,819member
    mjtomlin wrote: »
    I've read half way through the Reference Manual already... Lots of good stuff. I really like the removal of a lot of the baggage that came along with Objective-C in order to extend the Standard C syntax - although Apple has been hard at work at removing much of it over the passed few Xcode releases.

    Xcode 4:  
    NSArray *names = [[NSArray alloc] initWithObjects: @"Tom", @"Dick", @"Harry", nil];

    Xcode 5:
    NSArray *names = @[@"Tom", @"Dick", @"Harry"];

    Swift:
    let names = ["Tom", "Dick", "Harry"]



    Side note: Anyone remember Dylan? Another language developed by Apple in the early 90's.

    I'm pretty sure the Xcode 4 example you have compiles in NeXT Project Builder circa 1989. It's about damn time Apple moved Mac OS X programming into the 2010s.
  • Reply 15 of 93
    gwmacgwmac Posts: 1,807member

    I have no technical reason for stating this because I am no programmer. I can hold my on with some HTML and some scripts but when it comes to C and other languages I am lost. What I want to say is based strictly off a gut feeling, but I think Swift might not only be the biggest news this WWDC but possibly in many years. From what I can gather this is a leaner, meaner, more modern language that could allow an entire new generation and pool of talent that were scared to death of Objective C as being too difficult to even attempt to learn. All those people fluent in other languages shouldn't have many problems transitioning and learning Swift. It also seems a lot of the knowledge acquired with Objective C can be used with Swift.  So far it seems like Swift is a much less daunting language to learn. WWDC is sort of like the cement conference where they pour the foundation. In the fall the iPhone 6 and hopefully several other new products will be the skyscraper.

  • Reply 16 of 93
    tallest skiltallest skil Posts: 43,388member
    Originally Posted by mjtomlin View Post

    I don't know... Heres a swiftand another




    Originally Posted by Phone-UI-Guy View Post

    Have you not seen a swift in flight? Also, "Peregrine" isn't also a pun for it being really fast.


     

    Good points. Shame they couldn’t call it Swallow, though. Then OS 10.11 Capistrano would have been all the more fitting.

     

    Originally Posted by SolipsismX View Post

    It's also too close to the word perineum. image

     

    That joke nearly gave me peritonitis. 

  • Reply 17 of 93
    solipsismxsolipsismx Posts: 19,566member
    gwmac wrote: »
    I have no technical reason for stating this because I am no programmer. I can hold my on with some HTML and some scripts but when it comes to C and other languages I am lost. What I want to say is based strictly off a gut feeling, but I think Swift might not only be the biggest news this WWDC but possibly in many years. From what I can gather this is a leaner, meaner, more modern language that could allow an entire new generation and pool of talent that were scared to death of Objective C as being too difficult to even attempt to learn. All those people fluent in other languages shouldn't have many problems transitioning and learning Swift. It also seems a lot of the knowledge acquired with Objective C can be used with Swift.  So far it seems like Swift is a much less daunting language to learn. WWDC is sort of like the cement conference where they pour the foundation. In the fall the iPhone 6 and hopefully several other new products will be the skyscraper.

    I'm finding it insanely easier to learn. All that redundant looking code is just gone in Swift. So far I'm plugging through about the 5% of the eBook per day testing example. I hope to be able to incorporate it into proper apps within the month.
  • Reply 18 of 93
    ripperripper Posts: 7member
    I want to love Swift, but at this stage I just can't, not in its current state. I've only gotten through about the first 200 pages of the iBook but there are things that, IMO, could/should be more rationalized, particularly some of the syntax. A couple things off the top of my head:

    Variables are declared: var foo: Int
    That's fair enough, but then 'optionals' are declared: var foo:Int?
    That's too little of a difference (ok, I'm used to C's * for pointers and that's only a single character so...). Anyhow, so I want to use my optional, it's easy in a boolean context to determine if it has a value:

    if foo {...

    but in a scalar context I have to refer to it:

    bar = foo!

    or decompose it in the boolean context:

    if var bar = foo {
    // do something with bar

    But, that's not all. I could actually declare it:

    var foo: Int!

    What does that buy me? The ability to refer to it in a scalar context directly:

    bar = foo

    In the boolean context it's still interpreted as 'does it have a value' thus the context is clearly known in interpreting it. So, why two different ways to specify it and use it?

    In light of the contextual interpretation, I could argue that having all variables be 'optionals' by default would be a more natural and consistent approach. The compiler can certainly warn you if you're attempting to use it before assigning it a value and even if you ignore that warning it's a runtime fault to use it if it doesn't have a value. With 'optional' as the default (only?) type, all variables could be used in the exact same way; e.g.

    var foo: Int
    ...
    if foo {
    // do something with foo
    } else {
    // foo has no value
    }

    Second, the inconsistency between:

    let array = [a, b, c]
    let dictionary = [d : 1, e : 2]

    According to the documentation this creates, respectively, an immutable array and dictionary, except the dictionary is truly immutable and arrays are only sort-of immutable.
    While the dictionary cannot be changed at all and the array can't change size, the contents of the array can be changed. That's hardly immutable and certainly different from the true immutability of NSArray.

    That's probably enough for now for you all to take me to task. :-)
    I'd love something more modern than Objective-C, something where everything is an object, say. Or any number of other things, but as it stands, I don't think Swift is it.
  • Reply 19 of 93
    pokepoke Posts: 506member
    Quote:

    Originally Posted by gwmac View Post

     

    I have no technical reason for stating this because I am no programmer. I can hold my on with some HTML and some scripts but when it comes to C and other languages I am lost. What I want to say is based strictly off a gut feeling, but I think Swift might not only be the biggest news this WWDC but possibly in many years. From what I can gather this is a leaner, meaner, more modern language that could allow an entire new generation and pool of talent that were scared to death of Objective C as being too difficult to even attempt to learn. All those people fluent in other languages shouldn't have many problems transitioning and learning Swift. It also seems a lot of the knowledge acquired with Objective C can be used with Swift.  So far it seems like Swift is a much less daunting language to learn. WWDC is sort of like the cement conference where they pour the foundation. In the fall the iPhone 6 and hopefully several other new products will be the skyscraper.


     

    I think Swift is a sign that they're getting as serious about the developer toolchain as they are about consumer software. It's very interesting that Lattner has taken over the Developer Tools team. It fits the Apple model of having a "personality" at the top. I think it's very, very important when you look at it from a big picture perspective: Apple is going to be really pushing innovation in developer tools from now on. I think the important thing with Swift is that it will appeal to web developers, who will find it more familiar than the rather esoteric Objective-C. With this language, the changes to the App Store and CloudKit, we could see a big exodus of developers from the web to apps.

     

    What's really interesting to think about is that Apple probably has more data on programming bugs and performance than anyone on Earth, since it reviews every app that goes in the App Store, and must surely be using that data to drive the design of Swift. So what we have here might be the first truly empirically motivated programming language. From what I've seen briefly viewing the language, the focus is on safety, performance and concision, so this seems to be the case.

  • Reply 20 of 93
    rogifanrogifan Posts: 10,669member
    Of course ZDNET aka Microsoft's PR arm, pisses all over Swift. :rolleyes:

    http://www.zdnet.com/apples-new-swift-development-language-highlights-the-companys-worst-side-7000030150/
Sign In or Register to comment.