An Introduction To Apple’s New Programming Language: Swift

By : Amandeep Singh Chawla


This year at WWDC, the focus was so heavily on iOS 8 and OS X Yosemite, that what should have been the biggest news of the event, went rather under-appreciated. Apple introduced the Swift programming language to the world. This, to the end user, is barely news. However, to the developer community it might as well be a game changer. Certain programming languages have clear advantages over other programming languages, some are faster, some more efficient, some are just cleaner, some incredibly simple. Apple is the latest firm to create their own programming language after Google’s Go (Golang) and Microsoft’s .Net Framework. Swift Programming Language claims to have learned from these languages, while staying true to its Objective C predecessor. Apple claim to have created the fastest, most robust high-level programming language. Let us explain.



swift-banner

Why Do We Need Programming Languages?

There are quite a few ways to get a device to do ‘things’. Any device, from modern wearable gadgets to the traditional computers, can be made to do things using either the old fashioned way of machine language, writing in raw byte code/assembly language, crafting each instruction by hand; or you can rely on high-level languages that will help reduce some of the tedium. That’s why there is more focus on bringing developer languages as close to normal language as possible. We understand that the name of Swift attracts more developers than it does onlookers, but we will still simplify the explanation to help you understand the technology that will control future generations of Apple products.
A quick primer: Electronic devices are literally the dumbest things known to mankind, without all the programming, they would be reduced to mere ornaments. What gives them any real function, is the programming. At a very basic level, electronics need to be told, action by action, what they need to do, that’s what we used to do with punch cards and later with machine language. Then we moved forward in time to develop languages that let us communicate with machines in a relatively more natural way (yes, code is actually a simpler version of what it could be). We’d write code, it would be compiled into something the computer understands and then executed. So, to sum up, code-compile-execute.

Why Swift?

Now, you can imagine the most pertinent question being “Why?”. C, the language is from the 70′s, breaking considerable new ground at the time, then came its off-shoot , Objective C in the 80′s. Apple has been using that platform for development ever since. Logic dictates, “if it ain’t broke, don’t fix it”, and if it has been working for 30 straight years, what could possibly be the problem? Well, that. Apple has been using Objective C for decades now. Time for something faster, more powerful, easier. Enter Swift.
According to the official ebook on Swift (available for free on iTunes) “Swift is a new programming language for iOS and OS X apps that builds on the best of C and Objective-C, without the constraints of C compatibility. Swift adopts safe programming patterns and adds modern features to make programming easier, more flexible, and more fun. Swift’s clean slate, backed by the mature and much-loved Cocoa and Cocoa Touch frameworks, is an opportunity to reimagine how software development works.”
Swift Book Cover

Why Is Swift Important?

As much as Apple would like to have you believe in their wholehearted innovation, there has been an idea of “scripting” language. The traditional code-compile-execute parameters requires that you can see your code in action only after it has compiled. Compilation shows you exactly what your code is capable of. If your code has errors, the compilation will result in erratic behavior or crashes. Then the coder’s job will be to track down where the error lies, to fix it and then start anew. This process is both arduous and time consuming, but it is something the programming world has always lived with; it is the way things have always been. Scripting languages execute line-by-line so you can see results as you write, eliminating the need to review your code for errors at a later time. Making the process faster and that much easier.
To date, scripting languages have been limited in their abilities. Take Python for example, it is blazing fast, but it is also limited to simpler things with limited capabilities. Like a Forumla1 car, great for racing, not so much for getting the groceries.
If you want to make a game, then Python is not your go-to environment. However, Objective-C is (or C++ if you’re on Windows). Now, Swift promises the best of both (in fact, many) worlds, taking inspiration from Objective-C, Rust, Haskell, Ruby, Python, C#, CLU, and far too many others to list (reference: Swift developer/expert Chris Lattner). Swift claims to keep the good things and lose the bad things from the above. In key benchmarks its execution is faster than Python and much faster than Objective-C, so it is off to a good start.

What Else Does It Do?

Swift also brings a real-time visual environment called “playground” where you can see your result compile in real time, much like a scripting language. This, based on the design of the app, can bring entire processes down to a few minutes, because if something goes wrong, you will immediately know what caused it and can address it right there. It is the programming equivalent of fixing a mistake on a printout vs. fixing a red underlined word as you go along. Allowing you to create complex apps more quickly.
It goes a little deeper. For high-level languages, you were required to declare and access classes and libraries to engage functions, no matter how basic. in C++ You would need <iostream.h> and <conio.> in order to use basic input, output and datatypes in your code. In Swift, however, none of that is necessary. You would not need to declare any libraries, as Swift will manage what each datatype and io (input/output) function needs and will engage that library itself. So, printing something as simple as “Hello world”, goes from
#include<stdio.h>
int main(void)
{
  printf("Hello World\n");
  return0;
}
to a simple:
println("Hello, world")
That is the entirety of the code that needs to be compiled. You will also notice that the code does not use the dreaded “;” as a universal sign of an end statement.

What Are The Drawbacks?

Now, the existence of Swift does not mean the instant death of Objective-C and all its ways. Apps can still be created using Objective-C and native Objective C users won’t feel completely alienated as there are similarities in these environments. Of course, since Apple did just spend 4 years working on a new programming language, they will be focusing on pushing and supporting Swift, now and in the future. Perhaps one day they will erase Objective-C from the annals of Apple’s programming languages, but that day isn’t today. Though if a new language is out, one that is so easy to learn and is that much quicker, then why would anyone stick it out with Objective-C?
There are a few concerns of course, the immediate being the upheaval of the industry. Entire careers have been forged around teaching people how to make iPhone apps, those careers and their students have immediately become obsolete, there will be plenty of restructuring on that front. We will also be getting a new crop of early adapters to Swift (Flappy Birds already created using Swift), which is a good thing as well as bad. Good that new blood will be injected into the organism, the bad being that this new blood will be inexperienced and will flood the market with poorly made apps.
We will soon be discussing Apple’s metal framework, discussing its advantages and disadvantages, especially in iOS gaming.

Conclusion

In case you are wondering why there was no new hardware announced at the WWDC conference, then we’ll refer you again to our earlier statement that hardware alone can’t do anything until the software behind it does not work. So this was literally the biggest news of all-time. That we are getting a new handle on software that will change the face of all hardware, in the future. In order to get Swift, you will need Xcode 6 beta and a Developer ID.


You may also like

No comments:

Powered by Blogger.
//go.ad2up.com/afu.php?id=131698