SBP Blog

Swift: reinventing the wheel (Part 2)

Jan 29, 2015 by AdrianC

In the first part of this post I've described some of Swift's advantages and why Apple decided that it's time to move away from Objective-C. As shown in the previous article, Swift is a reimagined Objective-C, so (without entering into details about the latter) let's see what does Swift has to offer.



A closer look

Apple has decided that understanding the code is more important than writing it more easily, and so we see that Swift has adopted the trade-off which results in a more readable and understandable code (although it will be more time consuming to write it). In order to balance this, many things in Swift became optional: the method signature information that belongs to function calls, the semicolons that define the end of the line, the parentheses for logical evaluations.

In Swift, strings and numbers are treated more like objects, having properties associated with them. Also, by assigning a value to a variable, Swift will automatically initialize that variable with the type you used when declaring it.

Another improvement to Swift is getting rid of certain notorious C-like error-prone behaviors, such as: the pointers are exposed, assignments return values, variables and constants are not initialized.

Looking into the future

Many developers are arguing that it will take Swift some years to become a standard for iOS and OS X development - and so, while Swift is attractive to beginners, Objective-C veterans are not so keen to make the jump right away. In spite of this, learning Swift is profitable for beginners and veteran iOS developers alike, because when the transition between the 2 programming languages will be finished, Swift is going to remain the only programming language for iOS and OS X development.

In light of all this, Swift has its share of disadvantages though:

• It can be used only by iOS and OS X developers
• The code execution is slower than the one from Objective-C (although not in all cases)
• It needs time to become a mature programming language

In the end, developers who are worried that their Objective-C code is going to the Trash (the OS X Trash bin, of course :)) need to stop worrying, as Swift is compatible with Objective-C, meaning that the 2 programming languages can be used alongside in the same app. Apple’s intent is obvious, Swift and Objective-C will co-exist until the former will completely replace the latter.

Many developers have stated in the past that the end of Objective-C is near and that Apple needs to move forward. As a result, today we have Swift, "an elegant programming language for a more civilized age"* :)

Feel free to use the comments section below, to share your opinions or experience in using the Swift programming language.

* Paraphrasing Star Wars: "An Elegant Weapon, for a More Civilized Age"

Tags: Programming 


No comments yet.

Your Comment: