Swift Development for iOS… and Android with C++ and Object Pascal


Swift is the name of the new programming language by Apple, announced last week at the company developers conference. I’m pretty sure you’ve heard about it.
Swift Roundup
Here are some interesting links and blogs, with widely different opinions:

Apple’s official introduction to Swift: developer.apple.com/library/prerelease/ios/documentation/swift/conceptual/swift_programming_language/GuidedTour.html

Tim Anderson fairly balanced opinion at www.itwriting.com/blog/8483-apples-swift-programming-language-easy-coding-for-os-x-and-ios-at-last.html

ZDNet very critical voice (but picking C# won’t have been a nice idea to me, quite the opposite): www.zdnet.com/apples-new-swift-development-language-highlights-the-companys-worst-side-7000030150/

Performance doubts (but it is still a beta, too early to tell): www.splasmata.com/

What’s New and Different… from C / ObjectiveC: www.fastcolabs.com/3031400/whats-new-and-different-about-apples-new-swift-programming-language

Swift, Objectively by Dr Dobb’s (even if Andrew fails to recognize the features coming from Object Pascal, in the rather long list of languages this new draws upon): www.drdobbs.com/architecture-and-design/swift-objectively/240168424

Language Considerations (C++ and Object Pascal)
I think that RAD Studio, with C++ and modern Object Pascal, offers faster development and for more platforms. Development is based on an equally powerful language, but it is more visual, offers component previews and live data at design time. This is due to the libraries, but there is a clear language influence. Anyway with RAD Studio a single source code will work both on iOS and Android, not to mention Windows and Mac.
By comparison, Swift can be used only for Mac and iOS development, and given it is a proprietary language, it might remain limited to those two platform. Not that the scenario was very different in ObjectiveC, and certainly Swift seems a better and more modern language from what I’ve read so far.
What does this new language mean for the languages used by RAD Studio?

C++ remains a more open and flexible option. With C++Builder and Appmethod you use the same LLVM engine Apple leverages and embrace the same ARC memory management on mobile, you have a similar features set… but a more standard language and many common C++ libraries to use.
Object Pascal is very similar to Swift features-wise, again uses the same underlying architecture and can gain the same speed of compiled code. Given iOS developers will have to learn a new language, why not learn one that will give them support for more platforms (Android included)?

Swift vs. Object Pascal
How can we compare Swift to Object Pascal on mobile language-wise? Both languages can compile via LLVM, use ARC memory management, are strongly typed, have full support for object-oriented programming with single inheritance and multiple interfaces, both support generics, both have closures. The languages even share some keywords like self and override. And AnyValue looks a lot like TValue.
One more thing. From Tim Anderson article: “There is an interesting feature called Extensions which lets you add methods to any existing type. For example, you could extend Int with a prettyprint method and then call 3.prettyprint.” Object Pascal has the same exact feature, it is called helpers and can be applies to classes, records, and native data types. You can write “3.ToString” in Delphi XE6 on all platforms.
Where Swift has more flexibility is in the use of implicit types, tuples, and distinction between nullable and non-nullable types. What seems missing is exception handling, which I personally find quite odd. What I like more in Object Pascal is the use of properties, published, and streaming; named and virtual constructors and destructors, plus class references and class operations, along with rich reflection and attributes. I also prefer the way closures capture the execution context. But this could lead a lengthly debate on languages features, which I really don’t want to get into.
Temporary Conclusion
Personally, it is very interesting to see a new programming language coming, and I’m sure Swift will have a good following, because it seems nicer than ObjectiveC and many iOS and Mac developer will move to it. It might also be easier for C# developers to adopt it. Again, it is nice to see some ideas from Object Pascal in Swift, but I’m quite sure there are a couple of nice ideas in Swift that Object Pascal could borrow in the future.
One final question: With more (new) languages gettign wider adoption, will the language barriers reduce and will developer be more willing to be fluent in multiple languages?

Comments are closed.