It has been two months since Apple introduced its new generation of platforms, and with them, the company brought yet another programming language to the market.
THE Swift it has already been discussed here in some articles and is also being widely explored by developers around the world engaged not only in how to produce applications with it, but also in following its evolution, after all, we witnessed even a change in the way the company to communicate with its partners as a result of its new project.
New ”, incidentally, a force of expression: Swift has been working for Apple for years. For a long time it was a project of a man more precisely by Chris Lathner, who in the past has been behind other revolutions in development for Macs and devices running iOS. Outside the scope of launches for consumers and some related areas in which Ma's press and enthusiasts are more connected, technologies for creating applications have been of extreme interest to Ma in their products for years.
Even today, however, it was difficult to gain greater notoriety. But why? Next we try to reflect a little on Apple's history in technology and show what is fundamentally different about Swift.
In the past, a bet on uniting paradigms
As we have already said, Objective-C is the programming language that has permeated software development at Apple for almost 20 years. However, its history is much richer than that. It begins in the 1980s, with Brad Cox and Tom Love engaged in bringing to traditional C some concepts of a more modern language of the time, known as Smalltalk. It was a combination of object-oriented programming paradigms with the strength and tradition of those who gave rise to a good part of the most modern computer systems in the world.
This work was appreciated by NeXT, a company founded by Steve Jobs in his Apple “xodo”, between 1985 and 1996. In this period, NeXT outlined the main structures that would give rise to Mac OS X in the late 1990s, including the main pillars of the current framework Cocoa: AppKit and Foundation. The basis of all this development, of course, was Objective-C.
For the time, the bet was bold. No other company used Objective-C in technologies: in the following years, Java would take over the world because it was extremely more versatile and multiplatform; Microsoft would try to replicate the same with .NET and similar technologies for Windows, and in the midst of this, several technologies have emerged to foster innovation in development for the internet.
NeXT's baggage within Apple made Mac OS X an example of a solid and elegantly programmable operating system, but also a niche. Even today, we are 80 million users around the world, nowhere near what Windows or the web itself encompasses as platforms. But halfway through, Apple brought iPhones and iPads with it, taking the company to hundreds of millions of people, which helped spread the concept of using apps and, perhaps more importantly, creating them. No other audience as assisted by the company as that of developers, which has helped bring thousands of companies together over the past seven years. With that, Objective-C was able to gain greater notoriety.
In general, Objective-C is a complex language but it still serves us well today and will continue to serve indefinitely, for now: some of the best software in the world is in the current OS X and was thus created. But the iOS-driven community, since 2008, has always questioned many aspects of how Apple should operate and what its technologies should support. Then there was room for many improvements.
A gift of transitions
Between 2008 and 2014, several technologies passed through Apple's drawing boards and part of them were responses to a challenge: to make things easier to program. The deeper you go between the layers of a platform you need to go to get results, usually the greater the effort. This was true for the company in several areas, such as graphics and parallelism, multiprocessing and multimedia, among many others.
At the same time, the spread of other programming languages on competing platforms has made it possible to easily write applications capable of achieving the same quality with less effort, as well as adapting better to development standards that are constantly evolving. All of this made Objective-C show its age before the creation process on other platforms.
Apple showed improvements. For example, it created a modern compiler for its platforms, the current LLVM (one of the best on the market). From it, it launched functions to facilitate the development of its tools (such as static analyzes and self-correctors), and to facilitate the identification and correction of errors by developers. It even contributed to the end of dependence on pointers and object references from C and C ++ to manage memory, initially using garbage collection (but without reaching the effectiveness of C # and Java) and, more recently, with a new technology called ARC (for automatic counting of object references).
Many things, however, became patches around a programming language that carries heavy baggage. It was, according to Apple executives and engineers, that the question came: what if it didn't exist?
Understanding a little Swift
It is very difficult to create all the necessary structures to support native development in a new language. But Apple already had investments in it in place, controlling the entire development architecture for iOS and OS X. As a programming language for such a diverse audience, Swift was born fast. Unlike companies that in the past invented languages and then had to invent platforms as well, Ma already had a platform evolved for the present: there was only a language that could better interact with it.
Now, how better is that? Let's look at some resource examples below.
If you don't need to dig deep on a platform to get a result, you can program with less effort. In a programming language, this means having more techniques and functions at your disposal. Between Objective-C and Swift, Apple brought in a number of them, including:
- Implicit types;
- Modules, which eliminate header files (headers);
- Optional types;
- Operators overload.
Many of these new features are standards of other languages, but they are things that Apple developers can now count on as facilities, to make programs less difficult to maintain and easier to evolve. Allied to this, Apple created an environment of playgrounds where a developer can write quickly and see the results in action almost instantly, without the need to create an entire software project and deal with all phases of construction.
Even for the simplest of programs, there is a difference when programming. In Objective-C, one of the command line program templates that Apple provides with Xcode prints a line of text on the screen as follows:
Through Swift, a single line of code displays results on screen without the need for compilation.
In addition to creating programs, Swift also helps developers to interact with them through programming, even after they have been compiled. A feature called REPL (acronym for Read-Eval-Print-Loop) leaves an environment of scripts willingness to interact with applications running in real time.
For those starting out in development, using Swift can be a good possibility to avoid bad programming practices. Some of them are impossible in relation to what exists today for iOS and even for other platforms. Through ARC, developers do not have to deal with pointers to manage memory.
There is also no need to deal with variable initialization, since they are always ready before use. The language is also safe enough to avoid overflows and it has its own safety standards, trying to keep up with what current development practices require.
Because it was created to work with Apple's own LLVM compiler, the Swift language can work with several specific optimizations. Since its introduction at WWDC 2014, some developers have had a lot of fun analyzing how programs behave in certain scenarios compared to Objective-C.
Recently, Jesse Squires, a San Francisco-based developer, produced lengthy tests comparing various sort between Objective-C and Swift. The results vary widely depending on the code optimized for execution by the compiler and, in general, this is something that Swift depends a lot on. In some tests, algorithms ran up to 35 times faster than in Objective-C.
A new language for a new era
Commonly I say that in computing there is neither the best nor the worst, but what meets our needs. Between the criticisms of those who expected other attitudes from Apple and the expectation of becoming something revolutionary, I think Swift is in the middle. It will not be the best of all worlds for everyone, but we live with other needs than when Objective-C first appeared in 1983.
A modern language that is more aligned with what developers need today helps a lot, and the trend that we will have, yes, in the future.
Swift is not ready as well as OS X Yosemite and iOS 8. During my evaluation with other developers, we saw a lot that must change. It is something to get the books already published, to get acquainted and create new projects in living cases. Not least because Objective-C hasn't been going anywhere for a long time.
Furthermore, contrary to the view of some critics / enthusiasts, what I believe is that Swift is not enough to revolutionize anything, but rather to express one more vision in a new world in software development, which requires embracing new developers easily. When you have something more interactive in hand, the tendency for creative barriers on your platform to decrease, and many of the initiatives Apple takes around its technologies this year make it clear what makes the prospects for your future very promising.
You can't talk all about a programming language in a single article. Below are some recommendations for articles and books for those who want to check out: