A 21st century programming language for OSX & iOS - Swift - the progressive move from Objective-C!

June 01, 2013

Down arrow black
Mateusz Dzwonek

Apple has been running with Objective-C since 1983. Although it has stood the test of time with additions of certain frameworks, and the ability to always drop back to raw C if required, there are still pain points with this language that have been resolved long ago in other 21st century languages. Software development is evolving to focus on rapid development and less overhead when it comes to management of memory and optimised execution which a compiler can do perfectly well, leaving the programmer to focus on the functionality. Finally, Apple have introduced Swift to give their developers the same benefits that most modern languages have been providing for years.

Firstly, to go through some of the flaws with Objective-C. I’m not going to say it’s a horrible language, and i know a lot of iOS developers out there do see the beauty in it, as do I. But there are some fundamental reasons why Apple have chosen to introduce Swift.

  1. Objective-C is verbose! This is a heavy language with header files and long winded function names, and if your autocomplete is not giving you the right method, get ready to start writing essays. Objective-C’s answer to this was to introduce literals which lets you write certain data types in a shorthand format. This helps, but it’s not enough.
  2. Memory Management needs consideration. I know ARC (Automatic Reference Counting) has made a tremendous difference in this, but before ARC, if you did not follow certain principles, you will find yourself debugging for hours. This is also a plus for the language in that you control your memory consumption without garbage collection holding everything which helps optimization, but many developers now learning on Java, or C#, have an extra hurdle to jump when approaching Objective-C, and memory is an important one to understand.
  3. No modular code with namespaces. Namespaces or alike have been used in many other languages to help control the modular nature of todays programs. But Objective-C never jumped on board. Static libraries do let you create modules, but most Objective-C developers will hit type conflicts as SDK’s and code sharing is becoming more prevalent. To increase to the verbosity, developers now precede most classes with extra characters just to give class names uniqueness. This is completely backwards.
  4. Modern principles are largely omitted. Closures, Generics and Multi-value returns are some of the treats that other languages have provided us with to give us a little more power and speed when developing. Although Code blocks were introduced into Objective-C with GCD a few years ago, mixing this C code with Objective-C code just adds to the frankenstein that Objective-C was going to become.

I am aware that Objective-C is likely in the top 5 languages used today, But that is solely because of the momentum that Apple have gained with the release of iPhone’s and iPad’s and the associated SDK. But releasing Swift is a massive step in the right direction for Apple and their developer community. Here is why:

  1. Syntax is light and clean. It starts to follow the norm in readability between other languages. It will be easier for a Java developer to jump onto the iOS platform, and quickly grasp the development rules. This is a strategic move for Apple if it wants to adopt an even larger part of the developer community, it’s building a bridge.
  2. Namespaces pave the way for more modular code and sharing of libraries which is a natural progression in the direction modern architecture. And this also means no more header files! Welcome to year 2000 Apple.
  3. Closures, Generics, Multi-value returns and type inference are great features that will massively increase productivity and cleanliness.
  4. Complexity is removed. Some barriers for new developers on Objective-C is the usage of pointers, the odd code block syntax and memory consideration. With Swift I believe much of this will be removed and will let developers focus on their own architectures as opposed to the nuances of Objective-C.
  5. Their migration path does not leave anyone disadvantaged. This is important. Migrating to a new language is not easy when you have millions of developers who already know an existing language. Apple are using the common LLVM compiler so if you want to continue writing Objective-C you can, or you can start inserting your Swift code right in the middle of an Objective-C method. Nobody will have to take a step back, but I imagine the take up of Swift will be very quick, as the advantages will be too enticing for all existing Objective-C developers.

Apple have done this the right way, they are not only empowering their current developer community, but they are creating a larger door to recruit new developers onto the platform. It could have been a couple of years earlier, but I won’t hold that against them. Apple promote innovation and product progression, and it’s about time they echoed that philosophy in their development tools. Swift is a great offering by Apple for their developers, and I predict within 6 months, at least 90% of new app submission will be using this new language.