logoalt Hacker News

layer8yesterday at 8:13 AM3 repliesview on HN

As someone who hasn’t used the language, I’m curious about what the valuable lessons of Objective-C are that the programming industry is resisting learning.


Replies

jrmgyesterday at 10:42 AM

Weak, dynamic typing. Dynamic method binding at runtime (method calls really are message-sends). 'Traditional' object orientation with inheritance (although delegation and dynamic mixins are also core concepts, and the class hierarchy and method lists can even be manipulated at runtime). Nil is allowed anywhere and messaging (calling methods on) it is a no-op. Heavy use of 'notification' posting and subscription.

All of these are unfashionable nowadays, but they’re fundamental to Obj-C (some to the structure of the language itself, some just as idioms) and to the design of AppKit and UIKit.

Now, the fashion is:

Strong typing. Static binding at compile time with no runtime modifications to the type hierarchy. If OO is used, there should be minimal inheritance. Nullability is strictly defined in the type system, and acting on null objects causes, at its most forgiving, an exception, and at its least forgiving, program termination. Notification-based systems may be the outlier here (still in heavy use), but even they are often frowned upon for being too 'loose' and unanalyzable, at odds with the ideals of static typing and static binding.

mpweiheryesterday at 11:08 AM

Many, though I have to start with this disclaimer: I still don't fully understand why Objective-C is such a sweet spot.

One very important one is that, empirically, it showed how much of what we think we know about language design is ... shall we say ... "incomplete".

After all, Objective-C is a car-crash of a language: take some Smalltalk and jam it into C. Done. How can you write software with this? And yet NeXTStep and Cocoa/CocoaTouch, arguably the most elegant pieces of OS-level/UI-framework software ever, were written in Objective-C. And not despite of it, but because of it.

From a safety standpoint, it's hard to see how you can get worse: all the static type safety of Smalltalk (none) combined with the memory safety of C (none). And these interact.

And while it certainly is possible to use it very, very badly, in practice I haven't seen the horrors that we are supposed to get.

https://blog.metaobject.com/2014/05/the-spidy-subset-or-avoi...

As an example, we got the same level of improvement from doing an Objective-C → Objective-C rewrite with Wunderlist (from WL2 to WL3) that others claim for Objective-C to Swift transitions.

Also, dynamic messaging is said to be slow, yet Objective-C programs consistently outperform the much more static Swift ones.

https://www.amazon.com/gp/product/0321842847/ref=as_li_tl?ie...

And of course, we all know that to do dynamic OO, you need a large runtime and better yet a VM. But it turns out that you can get much if not all of it with a tiny sliver of an extension to portable PDP-11 assembly language.

https://blog.metaobject.com/2024/08/objective-c-is-just-like...

With so much being provided by so little, you can actually put the rest of the language design space to better use, IMHO:

https://objective.st

dwaiteyesterday at 4:40 PM

[dead]