Tuesday, August 18, 2015

A Eulogy for Objective-C

Aaron Hillegass (comments: 1, 2):

The wonderful thing about Objective-C is that it’s so dynamic. As we start moving into languages that are a little bit more uptight about such things, it’s nice to take a moment and think about the huge benefits that we get from some of this.


Loose typing made a lot of things that were difficult in other languages much easier, or possible. It also made bugs that didn’t exist in other languages possible as well. And you embrace that as an Objective-C programmer. You’re like, “This is a language for smart, pedantic, uptight people. I’m going to be very careful and do the right thing when I’m typing in names.”


One of the things that made the performance of Core Data so great, and made this faulting mechanism so seamless, is the ability to do isa swizzling. Once again, this could be very dangerous, but in the right hands it was a really powerful mechanism.

Another thing that you could do was actually create classes at runtime. It was pretty rare, but this is actually what made key-value observing possible.


Here’s one that people take for granted at this point, but it’s something that at the time was crazy: categories. The idea that I could take a class that NeXT had sent me, add methods to it, and then use that inside my program - that was really, really weird in object-oriented languages at that time. And it really scared Java people. […] As a result, not everybody had to write their own NSString class. Which is a really common problem for a lot of languages.

4 Comments RSS · Twitter

I think most of these Objective-C vs Swift comparisons are way off. Have any of these people actually tried to write code in Swift? Swift 1.0 was unusable, but praised by all. I find Swift 2.0 quite pleasant to use and I don't like it when I have to go back to Objective-C for some legacy or bridging code.

But the key issue with both languages has nothing to do with the language. Cocoa is the real determinate here. It is Cocoa that is a limiting factor in both languages. There were some great features about Objective-C, such as exceptions, that were unusable with Cocoa. The same is true about Swift. Generics are incompatible with Cocoa. Swift is strongly typed for simple types, but not objects. Since I need Cocoa compatibility, my classes need to be NSObjects. I have to cast down with am if let, but that is pretty automatic now. That is how Objective-C worked too.

"Swift 1.0 was unusable, but praised by all."

Remember Xcode 1.x? This was all the same. I'm waiting for Swift 6.0 ;-)



Now your wait is over, Swift 6.0 is here :)

Leave a Comment