Can Swift replace Objective C?

  • 2020-05-06 11:43:34
  • OfStack

The point of my article is that with all the information Apple has given so far, the language will not replace ObjC, it is not the next generation of ObjC. It has many disadvantages that make it not enough for large projects. These shortcomings make Apple itself not use it to do Mac/iOS app. I wouldn't rule out a big improvement next year or so, but at least not yet.

So if you're going to ObjC, you don't have to look at it.

But if you ask me if this language is important to the average developer, and I say yes, I can tell you that explicitly -- it's the big language that Apple introduced to the world at WWDC -- how can I say it's not important? It lowers the barrier to entry. Enable a large number of JS, Python, Ruby users to use Apple's technology to develop programs for them. What it does, like Core Data, Interface Builder, is it allows you to quickly write a program that works. But if you want to do some serious work, you can't. So Apple doesn't use Swift, just like Apple's Mail doesn't use Core Data, iPhoto doesn't use UICollectionView, App doesn't use Interface Builder, Apple doesn't use Swift. It just gives a small team of three or five people the ability to quickly make programs that work, and big companies the ability to quickly make Prototype.

====

Some people say it's equivalent to C#, or equivalent to Scala as an improvement on Java, and I can tell you that Swift is not. It's more like an toy language that you can quickly prototype.

There have been calls for Apple to post the next generation Objective-C. Ars Technica, who writes tens of thousands of comments a year on OS X, wrote Apple two years ago. Apple should make a language, Objective-C without C and use more modern features and shorter API, as well as support for automatic type derivation. For the article, see OS X 10.8 Mountain Lion: the Ars Technica review.

But Apple apparently doesn't take the language seriously. Obviously, they don't want to replace ObjC at all. And in Apple style, if they treat Swift as the future of ObjC, there will surely be one or two iOS/Mac apps that will be rewritten using Swift. (for example, when Apple was cutting Carbon, the first thing it did was rewrite Finder).

From a language perspective, Swift has too many disadvantages:

Its standard library is poor, with only Dictionary, Array, String and several data structures, not even Set. You want something else? You still have to use ObjC. Yes, it's faster than ObjC when you use native data structures. But that's just a few. It does not have any support for asynchronous/synchronous programming. It doesn't bind to Grand Central Dispatch, so any serious web application can't be written at all.

It does not have any protection mechanism (private, protected), and all method and variable are globally visible, which obviously cannot meet the needs of serious engineering projects.

You can only interact with ObjC. If you want to use C or C++ properly, you have to write wrapper for ObjC. This basically limits you from using a lot of C/C++ library functions.
There is no way to catch Objective-C exception, if once out of exception, your App immediately collapsed. This also basically limits you from using a lot of the old ObjC code base.

Chris's shortsightedness was evident in his design of the language. It's not unusual that he's a compiler guy, not a language guy. So this language, which claims to support functional programming, simply doesn't have the functionality that is common to most functional languages:

The only support is in lazy, closures, and simple functional language functions (such as map, filter). All of ObjC can do
No pattern matching
Type derivation is almost the same as C++11, without hindley milner
Based on these features, Apple is only positioning itself as a toy language to lower the learning curve for developers struggling with ObjC. Each of the first five is pretty much fatal, so Apple's own project won't use it. It's ok to make an prototype to the proof of concept early proof of concept.

I can imagine how easy it is to implement Swift (LLVM is mature, and writing a new language is getting easier and easier, such as making a small language in a few steps: 1. Kaleidoscope: Tutorial Introduction and the Lexer), but it is possible that Apple will solve these problems in the future and make it really useful. But for now, Apple doesn't want Swift to replace Objective C.


Related articles: