Wednesday, 22 November 2017

Is Swift 4 horrible?

The project team of Boochord iOS recently reached the first version milestone for iPhone and is publishing on iOS App store and preparing to utter the joys to sky.

It employs Swift language version 4 as the primary language and the tool of XCode, AppCode, Cocoapods etc. Many people know the "famous" incompatibility between Swift different version and the pet peeves about String processing performance, optional design etc. How does the project team go through all caves and traps to arrive the status today? I would like share some experiences with you.

First, optional design is a good one which helps junior person to avoid many "nil", aka, null dead end problems in java / c environment. But it does not mean nil bugs are fully eliminated since the enforced optional unwrapping is still some times unavoidable. And besides, best practices within a team could vary depends on third party used and member preferences etc. e.g., guard vs if statement. So agreement on early time is always important to avoid the code messing by many ifs.

Second, string processing is kind of pain for those with Java background. Since the indexing is not by integer but String.Index. And String can not be easily converted / processed in the form of charater Arrays. It would be easy to fall into the performance trap considering there are also big difference on low level String functions. String's UnicodeScalar view is indeed useful in some situation but they are always useful. However's by our experiences, a bad design and implementation could be 100 times slower than Android processing. We are using IPhone 7 plus comparing to kind of middle level 3 years aged android brand phone like Xiaomi etc.

Third, XCode is kind of robust but sometimes staggering and slow. The source code is compiled and running but it still shows there are some code error. Sometimes we have to delete the derived data of compilation to get a clean visual world. But the good side is that it is dead seldom while AppCode does although it does better and quicker refactoring job like renaming, moving etc. I cannot see it is a shame of jetbrain because it is performing much better as in Android Studio.

Fourth, Interface builder is the proud of Apple and has very precise and flexible control to place graphical components at right places. Its auto-layout has much better and clear intuitive presentation of constraints than Android GUI designer in my point of view. But be very careful to use XML source view to edit story board / nib file. It is reckless and rude change probably from Apple's point of view. Because you could fail to start Xcode unless you can fix the error by external tool like vi or other text editor.

Fifth, third party integration sometimes out of control. As many as 50 percent cocoapods did not function at first installation and needs some tweaks / work rounds. And Swift package managers is still in infant phase could not provide meaningful help. Manual import in XCode seems the final solution almost in all cases. But the method brings in potential manage risk on package management for many processes that requires automation such as testing, upgrading, merging etc.

Overall speaking, Swift is evolving to a mature language and the version of Boochord is reached in as short as 3 months and passed all the tests with few bugs. Considering it is has many complex components of intensive timer tasks, incorporated many Artifitial Intelligence generated data marks, and many members are junior or with different tech stack experiences and they are confident with Swift now, I would like to say Apple did a good job in last year to make Swift competitive.
Post a Comment