- 26 May , 2016
- by Vikrant Singh
- 0 comments
- 916 Views
Old languages never die they just fade away but development companies who stick with old languages are bound to see an early grave.
Such is the case when we talk about Objective-C and Apple’s strapping young swain Swift. Thanks to several key features, Swift has the potential to become the de-facto programming language for creating immersive, responsive, consumer-facing applications for years to come.
While Apple hasn’t stated all its goals for the language yet, the launches of Xcode 6, Playgrounds, and Swift together signal Apple’s intent to make app development easier and more approachable than with any other development tool chain.
Here are 9 reasons to get ahead of the game by starting to work with Swift now.
1. Swift is easier to read
2. Swift is easier to maintain
Legacy is what holds Objective-C back. The language cannot evolve without before the evolution of C. C requires programmers to maintain two code files in order to improve the build time and efficiency of the executable app creation, a requirement that carries over to Objective-C.
Swift drops the two-file requirement. Xcode and the LLVM compiler can do work behind the scenes to reduce the workload on the programmer. With Swift, programmers do less bookkeeping and can spend more time creating app logic. Swift cuts out boilerplate work and improves the quality of code, comments, and features that are supported.
3. Swift is safer
Optional types make the possibility of a nil optional value very clear in Swift code, which means it can generate a compiler error as you write bad code. This creates a short feedback loop and allows programmers to code with intention. Problems can be fixed as code is written, which greatly reduces the amount of time and money that you will spend on fixing bugs related to pointer logic from Objective-C.
4. Swift is unified with memory management
Swift unifies the language in a way that Objective-C never has. The support for Automatic Reference Counting (ARC) is complete across the procedural and object-oriented code paths. In Objective-C, ARC is supported within the Cocoa APIs and object-oriented code; it isn’t available, however, for procedural C code and APIs like Core Graphics. This means it becomes the programmer’s responsibility to handle memory management when working with the Core Graphics APIs and other low-level APIs available on iOS. The huge memory leaks that a programmer can have in Objective-C are impossible in Swift.
5. Swift requires less code
Swift reduces the amount of code that is required for repetitive statements and string manipulation. In Objective-C, working with text strings is very verbose and requires many steps to combine two pieces of information. Swift adopts modern programming language features like adding two strings together with a “+” operator, which is missing in Objective-C. Support for combining characters and strings like this is fundamental for any programming language that displays text to a user on a screen.
6. Swift is faster
Dropping legacy C conventions has greatly improved Swift under the hood. Benchmarks for Swift code performance continue to point to Apple’s dedication to improving the speed at which Swift can run app logic. The enhancements also enabled Swift to outperform C++ for the Mandelbrot algorithm by a factor of a mere 1.03.
Swift is nearly on par with C++ for both the FFT and Mandelbrot algorithms. According to Primate Labs, the GEMM algorithm performance suggests the Swift compiler cannot vectorize code the C++ compiler can — an easy performance gain that could be achieved in the next version of Swift.
7. Fewer name collisions with open source projects
Swift provides implicit namespaces that allow the same code file to exist across multiple projects without causing a build failure and requiring names like NSString (Next Step — Steve Jobs’ company after being fired from Apple) or CGPoint (Core Graphics). Ultimately, this feature in Swift keeps programmers more productive and means they don’t have to do the bookkeeping that exists in Objective-C. You can see Swift’s influence with simple names like Array, Dictionary, and String instead of NSArray, NSDictionary, and NSString, which were born out of the lack of namespaces in Objective-C.
8. Swift supports dynamic libraries
The biggest change in Swift that hasn’t received enough attention is the switch from static libraries, which are updated at major point releases (iOS 8, iOS 7, and so on), to dynamic libraries. Dynamic libraries are executable chunks of code that can be linked to an app. This feature allows current Swift apps to link against newer versions of the Swift language as it evolves over time.
9. Swift Playgrounds encourages interactive coding
Swift’s newly introduced Playgrounds are a boon to experienced developers. The Playgrounds were partially inspired by the work of former Apple employee Brett Victor. Playgrounds enable programmers to test out a new algorithm or graphics routine, say 5 to 20 lines of code, without having to create an entire iPhone app.
Apple is focused on providing the best consumer experience and is building only those features deemed worthy of attention. With the Swift 1.2 release in Xcode 6.3, Apple has already fixed thousands of bugs reported with the popular Apple Bug Reporter utility. The team supporting the development and evolution of Swift is very interested in how the language can be improved to better support the development community that builds apps and systems using Swift.
Ultimately, Swift is a more approachable full-featured programming language that will allow developers to not only build apps but also target embedded systems like the new lower-power Apple Watch for many years to come.
I hope you enjoyed the article. For more of such posts subscribe to the blog and we will keep you updated.