Tuesday, June 24, 2014

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

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

10 Early Thoughts on the Swift Programming Language

As of the time of this writing, just about 48 hours ago, Apple unveiled the Swift Programming Language. Normally, there would not be so much buzz about a new language, but due to Apple’s relative dominance in the mobile, and decent presence in the desktop market it is probably safe to assume that this language will at least have an impact on some businesses.

At codecentric, knowledge leadership is one of our core values and thus it is no surprise that some of us started reading the language guide right away. I am one of those curious ones and have to admit that I did not finish the whole book (860 pages…) before starting to play around with it.
Actually, I think this is encouraged by Apple as the new Version of Xcode (6 beta), which is needed to try out Swift, provides you with “Playground”. Basically this new feature is a REPL, an interactive toplevel or language shell, that allows you just to write some code and evaluate its results on the fly. Swift makes this especially easy since it provides you with a global scope in which you can write code without any need for classes or main methods.
Despite the fact that I would encourage you to jump into the Apple provided language guide “The Swift Programming Language” directly, I also invite you to take a look at our Swift playground repository. Aside from other interesting tidbits regarding the language, we also compiled a short tutorial. It is aimed at people already familiar with other programming languages, such as Java, and just gives a very brief overview in about 350 lines of code on the basics of the language. Go ahead and take a look, especially if you just want a very condensed version of the first few hundred pages of the book.
Aside from announcing the repository, I would like to use this blog post to give my personal opinion on some of my preliminary findings. Background info: I have done a lot of programming in Ruby, Java and Objective-C before. I limited myself to five points “for” and “against” to keep this brief.

5 Things I Like

The syntax. I have been a fan of Objective-C’s syntax mainly because of the named parameters in methods. While Java gives you foo(true, false, 0, 1, null), calls to objC methods are much clearer. So are the ones in Swift. I also like much of the other syntactic stuff, eg. -> for announcing return types, tuples, the clean closure syntax as well as the ? and ! notation, which brings me to the…
Handling of nil (null). I think it is quite fundamental that the language requires you to address nil explicitly and that nil is not a pointer to nothing but a invalid value, rather. The way you can handle values that might be nil using ? (question mark), which even can be chained, is very nice and reminds me a bit of the try method from Rails.
Strictness. This is probably (what isn’t?) a matter of taste, but I like it when the compiler tells me right away that I have done something which I should not have. This usually does not happen in script languages (unless you are using a really good IDE). Also, I think, eg. type safety and other “strictness features“, encourage good programming principles and well written code.
The Playground. It is just convenient to being able to have some place to just try stuff out and Apple did a great job here, allowing you a remarkable amount of insight into what your code does. At first, I thought this would be something like irb in Ruby but it really is much more and well done.
Its (future) adoption rate and support. As mentioned above, these days, there seems to be new programming language coming out every day. I guess most of you have taken a look at some of these but aside from the mainstream, none of them seem to receive much attention or actually become relevant for day to day business. With Apples mobile platform dominance and decent desktop business this will be much different. This language will not be mainstream soon, but there will be many more job openings requiring Swift knowledge than eg. Rust, which is quite similar. I like this because I think, all in all it is a nice modern programming language, despite the things that I am about to mention in following section.

5 Things I Am (at Least) Skeptical About

Any and AnyObject. It seems, when using the Cocoa API, which still relies on Objective-C and C you sometimes get return values of AnyObject. For example dequeueReusableCellWithIdentifier(String) does not return a UITableViewCell?, as I would have expected, but AnyObject! (note the !). This can actually hide an objC nil value. I guess usage of these will be reduced in later API releases.
Extensions. I kind of do not like the “patching“ of classes in Ruby. Now you can bring your own methods and even initializers to existing classes in Swift, as well. I could not find documentation on about how conflicts are resolved when two extensions try to provide the same methods. I guess it will be just an compile time error, which could make it (very) hard to use third-party provided frameworks, since everyone will patch their own convenience methods into String and Array.
Array. Speaking of which, Array shows in my opinion some strange behavior when extended in size. If a and b reference the same Array and you append to a, b will still reference the old Array and a will now be an entirely different object. This might be related to the fact that you seem to be allowed to make assignments to self within an object. A bit odd.
Dynamic(ness). While Objective-C seemed quite dynamic to me, the strictness (which I liked, I know) seems to disallow features such as calling methods by name of getting values of properties whose name you only know in a String. From reading the manual I would not know how to write a JSON to Object mapper, for example. Maybe I missed this, maybe this going to be implemented later on.
Stuff that seems to be missing. First and foremost: No access control? Seems a bit odd to me. Also I could not find out how to make properties read-only from outside the class scope, also exceptions and errors are not really covered. The docs say something about errors at runtime that might happen but not how (or even if) you can react. Also no mention of a multithreading mechanism. I guess there will be wrappers around for NSThread, but NSArray for example provided nice closure (or block) ready methods to iterate in parallel over its elements. I could not find some replacement to this, yet. There is probably a lot more that is just not there, yet, so I would not stress the missing stuff too much.

Wrap-up

To summarize, I think I personally would like to write code in Swift. Especially seeing it just as a replacement for Objective-C in OS X or iOS development, the language reduces a lot of “boring” overhead. However, when I think of a new idea – whatever it is – to shout out, “Yes! I am going to do this in Swift!”, the language – at least for now – lacks in some areas I deem important.
Have you tried it yet? Let us know your findings in the comments!

Building Apps with Parse and Swift

Building Apps with Parse and Swift

On Monday at WWDC 2014, Apple released a new programming language called Swift. As always, when we see that developers are excited about a new language or platform, we work quickly to make sure Parse can support that momentum. We’re excited about Swift because it brings a whole host of new language features to iOS and OS X development. Swift’s type inference will save developers a ton of typing and generics will reduce runtime errors by giving us strongly-typed collections. To learn more about Swift, checkout Apple’s reference book.
One of the best things about Swift for existing iOS developers is that it’s fully compatible with existing Objective-C libraries, including system libraries like Cocoa and third-party libraries like Parse. To start using Parse in your Swift projects:
* Add a new file to your project, an Objective-C .m file.
* When prompted about creating a bridge header file, approve the request.
* Remove the unused .m file you added.
* Add your Objective-C import statements to the created bridge header .h file:
#import <Parse/Parse.h>
// or #import <ParseOSX/ParseOSX.h>
This StackOverflow answer gives a more thorough explanation.
Once you’ve added Parse to your bridge header, you can start using the Parse framework in your Swift project. To help you get started, we’ve added Swift example code to our entire iOS/OSX documentation. For example, this is all you need to do to save an object to Parse:
var gameScore = PFObject(className: "GameScore")
gameScore.setObject(1337, forKey: "score")
gameScore.setObject("Sean Plott", forKey: "playerName")
gameScore.saveInBackgroundWithBlock {
    (success: Bool!, error: NSError!) -> Void in
    if success {
        NSLog("Object created with id: \(gameScore.objectId)")
    } else {
        NSLog("%@", error)
    }
}
To then query for the object by its id:
var query = PFQuery(className: "GameScore")
query.getObjectInBackgroundWithId(gameScore.objectId) {
    (scoreAgain: PFObject!, error: NSError!) -> Void in
    if !error {
        NSLog("%@", scoreAgain.objectForKey("playerName") as NSString)
    } else {
        NSLog("%@", error)
    }
}
That’s everything you need to know to start using Swift with Parse. For more examples, don’t forget to visit our iOS/OSX documentation. We can’t wait to see what you build with it!

For more: http://blog.parse.com/2014/06/06/building-apps-with-parse-and-swift/

Developer’s reviews on Apple’s new swift programming language

Last Monday, Apple makes surprise to developer with its new swift programming language which is for iOS and OS. They announce that this new language is in beta until iOS 8 introduced in the market-Apple’s replacement for objective C and they deem it as biggest decision ever made in past and developer claim it as much faster and easier to use. Yet Apple does not let away oldest language which actually have codebase that contain both objective-C and swift happily.
Objective- C, it’s over 20 year old currently with various praising for dropping on aging Facebook on twitter has been mixed and it yet providing the benefits of using modern programming language that other cannot please.
Apple says that they were doing work on Swift many years earlier, yet it has become very familiar with veteran developer which will be familiar in future with global developer. Along with faster feature it provides good closure, type inference, generic, namespace and multiple return types.
Apple also said that this new language is easier to learn and help developer while processing for they has developed interactive playground. We further share my query about this new language and what the developer reviews they gave:
interactive playground
A new Apple:
Steve Strenze said- he is exciting to have this and praise Apple that ‘they start this transition’ as swift which modeled after the benefits of Objective-C while putting a good syntax and style on it. He says that it bring me to rethink how should I design my own API, with more thoughts and emphasis he assumed how to place that on it which conveyed but overall he doesn’t expect good result but this new language work very optimistically- ‘the hump of learning to program in a new language’.
He stated that both swift and objective-c work very effectively together in such a form that they seems to build pretty different assumption about how code will written and how API’s return data; it is still  unclear that how it will work when there is conflict while interaction.  (READ ALSO:- Best 7 Apps for Apple iphone)
He spoke and pointed one more concern that whether developer will adopt this language or still rift occur because many were using oldest platform or many were not supporting this changes. Despite Strenze concern, he also says that it would be fully adoptable in future and it would be little silly for iOS and Mac developer to not have at least basic comprehension of the language.
Kevin Ingersoll
||a web developer based in San Francisco, explained over email that “the barrier to entry looks much lower for a web developer than Objective-C, and that’s what makes me excited about Swift” and that he’s had ideas for apps but “having to invest the time into learning Objective-C was the biggest hurdle for me – that hurdle is now gone.”||
Quentin Zervaas
||A developer in Australia, built a popular public transport appbelieves that Swift “reinforces that Apple is serious about making their developer tools and development workflow as easy to use, as well as looking for ways to constantly squeeze extra performance from devices.”||
Zervaas is looking ahead to evaluate real time and debugging of code using the language and think it will simplify many syntax for developer; as he spoke earlier that he is awkward looking language but still he define it good news.
Users on hacker news also get excited
With nln writing that even as a non-developer the changes make him feels more comfortable starting to learn how to build apps for iOS.
RC4_Encryption
Strategy concern:
Everything has flips side aspect; Five year experience developer Mike Said, ‘kind of annoyed by the release of Swift” pointing out that he likes Objective-C and doesn’t want to learn a new language. He continued, saying that “the advantages of Swift over Objective-C are unclear to me. At first glance this looks like innovation for the sake of innovation.” (READ ALSO:- Apple assure $ 3 billion earning amount of beats)
-“Afraid that Swift is going to be used just for the sake of it and that it won’t offer any real value”- because he said that he is going to give a shot for this language. This is where a divide could open up between old hat and new developer to the platform that use swift.
The excitement of WWDC was palpable; because response measure in collective wow. Because they assumed that what proportion of developer will adopt swift and on which timeline.
Swift proves it as a revolutionary declare which would be good language platform for Ios and Mac app performace and for developer.