[Thoughts] SWIFT - A major change in the future of development

Swift has matured quite rapidly and reached 2.0, it has been a phenomenonal effort from Apple to support a new langauge. Especially at a time when a majority are following it on a regular basis. I have spoken to many a developers and even some successful startup CEO's, the top question that most had was, How is Swift? This indicates a couple of things.

How is Swift?

This question implies that they have not as yet had a chance to pay with Swift and definitely not using it in their production environment. So the adoption of Swift in production is not as rampant/common as compared to other technologies.

Why have others not adopted Swift?

The other top question asked is 'Why' have others not adopted Swift. There are a couple of answers to this question,
1. It depends on their IT advisors, which can range from their 10 year old to their trusted accountants or their best developer. They do not know and do not recommend, so the organisation/company/developer does not adopt new technology
2. A more logical reason is that many sit in the stalls and watch the early adopters fail to go, "I knew so"
3. A mature and reasonable explanation is that many of the established organisations have codebases in other languages, namely Objective-C and their developer base is very good at what they do. The developers do not have the time to re-orient themselves with Swift (they might have played with it while on public transport) and could also be elitists/machoists as to resist moving to the easy options. Since Swift is a newly introduced langauge, there are a lot of features that might not be available 1:1 as with Objective-C, so they want to be certain about the transition. Adoption of ARC was not instanteneous either.

What do I feel about Swift?

After having written the book More iPhone Development with Swift from Apress, the code that was originally Objective-C was translated into Swift. So you can now use Swift, it had no Objective-C code, pure Swift code. Swift could not do everything 1:1 as Objective-C code did. The book started with Swift 0.8 and soon Swift 1.0 was released, this forced a lot of changes to the text and source code, by the time the book was published and marketed, Swift 1.2 was released, the source code (accompanying the book) was updated.

The point is that Swift is changing quite at a rapid pace, at the time of this Swift 2.0 is available with Xcode 7 but in beta.

Some very good points are made on Twitter, specially this article by Rob Napier.

My take, from a different perspective is that Swift is not just a new langauge, but is imparting a new way of thinking, a new way to develop. Functional Programming was already present but not as glamourized as it is now with Swift. Learning Swift is not about learning a new langauge, but learning a new programming paradigm. This is in my opinion a major reason for it remaining a hobby than being used in production. Yes, other things like the ever evolving nature of Swift and it's own limitations and bugs are also contributing factors.

What do you mean paradigm shift?

In the past the most common methodology was to subclass, Swift has made developers think about protocols and extensions, admitedly, these are nothing new, but after being introduced with swift, they are an important feature of development.

The other feature is enums and structs. These are amazing and are as powerful as classes. They cannot hold stored variables as yet, but can have functions. With Swift 2.0 the enums also have a string descriptor, the same as the name of the case value.

for example
enum Languages{
   case English
   case French
   case German
 }
 
 var eng = Language.English
 print("\(eng)")    // -> This will print Language.English

The enums can be more complex and have associated values that make for very interesting programming.

for example
enum ReturnType {
    case Success
    case Error(Int, String)
}

func someFunction(number:Int) -> ReturnType {
    if number == 5 {
        return ReturnType.Success
    } else {
        return ReturnType.Error(number, "The number is not the winning number")
    }
}

var theResult = someFunction(3)
switch theResult {
    case .Success:
        print("All OK")
    case .Error(let code, let message):
        print("Error \(code):\(message)")
    default:
        print("??")
}

Compare this to the simple return values or tuples, in this example the return values are much more verbose and usable.

Summary

There are a lot more features and quite many atricles about these features. My opinion on Swift as the title of this article suggests is that Swift is not just a new language, but will change the way code will be written in the future.

Comments

Popular Posts