``` 为什么选择Objective-C ```
Why Objective-C

原始链接: https://inessential.com/2026/02/27/why-objective-c.html

作者之前曾大力倡导移除Objective-C代码(在Audible已移除数十万行),却意外地发现自己又愉快地开始使用它。 最初打算用Python重写一个博客生成器,但他们放弃了这个努力,并考虑了Swift、Rust、Go和C,优先考虑速度。 最终,对超越C结构的数据建模功能的需求使他们回到了Objective-C——他们现在欣赏这种语言的小巧、易于理解和稳定性(极少的未来变更意味着更少的技术债务)。 尽管它的语法有些古怪,但作者发现这次体验令人愉快且富有成效。 由此产生的应用程序SalmonBay,一个静态网站/博客生成器,可以在不到一秒钟内构建作者的25年博客。 它作为开源提供,但并非 intended for 广泛使用。 这种经历展示了对先前“拆解”技术令人惊讶的回归,这源于实际需求和对它独特品质的重新发现。

一个 Hacker News 的讨论反映了人们对 Objective-C 的怀旧之情,尽管 Swift 已经非常普及。用户“vintagedave”分享了一篇博文,质疑苹果在从 Objective-C 过渡到 Swift 时是否陷入了“第二次系统综合症”,认为 Swift 的复杂性感觉像是过度设计的替代品。 其他人也表达了类似的观点,指出 Objective-C++ 对于使用 C++ 库的 macOS 应用程序仍然很有价值,因为它比 Swift 目前提供的集成更流畅。一位用户强调了 ObjFW,一个跨平台的 Objective-C 框架,作为一种可行的替代方案。 对话中还幽默地为 Objective-C 独特的方括号语法辩护,解释说它在视觉上代表着发送消息——就像一个“ASCII 信封”。总的来说,这个帖子表明人们即使在 Swift 占据苹果开发主导地位的情况下,仍然欣赏 Objective-C 的简单性和实用性。
相关文章

原文

In my previous post I talk about how I got rid of hundreds of thousands of lines of Objective-C code while at Audible and I explain why keeping Objective-C code around is a terrible idea. And I explain that…

I’m not stuck in the old ways; I’m not the guy insisting on the supremacy of Objective-C despite the obvious evidence against. I’m the guy who got rid of Objective-C — with glee and (oops, sorry Audible marketing team for the screwup) wild abandon!

Then of course I wrote some Objective-C code recently and really, really loved it.

Command line app

I wanted to replace my homegrown static website/blog generator because I no longer wanted to use the language it was written in, for reasons.

I took it as an opportunity to learn Python — but it turned out that my heart wasn’t in it (not Python’s fault; great language) and I ended up screwing it up. (See Blog Fuckup).

I thought about some alternatives: Swift, which I know well; Rust and Go, which would have the advantage of helping me branch out from the Apple ecosystem; and good old C, my happy-go-lucky friend who still sprints faster than every brash new language.

Of those I was leaning toward C because speed is an issue. I wanted to make rendering this blog, over 25 years old and with thousands of posts, to happen in under one second. The system I was replacing took a few seconds. But I wanted more speed (personality flaw).

And then I thought, I swear just for a split second, about how great it would be if C had something a little nicer than C structs for modeling my app’s data — and oh well too bad there’s nothing like that.

And then I remembered Objective-C, which is C plus some things a little nicer than C structs. 🎩🦖

Objective-C looks insane

Anyone new to Objective-C thinks it’s difficult and maybe a bit harsh because [[those squareBrackets] lookInsane:YES].

Once you get past that, which takes a day or two given a good-faith effort, you’ll realize how small a language it is, how easy to hold in your palm and turn around and understand all sides of it. And you’ll appreciate how easy it is to make good decisions when you don’t have a surplus of language features to choose from.

And you’d be reassured to know that Objective-C is probably never going to change, which means tech debt will accumulate much more slowly than with newer languages. (Unless, of course, you count Objective-C itself as tech debt. You don’t have to, though.)

It’s a cliché to call Objective-C a more elegant weapon for a more civilized age. It’s better thought of, these days, as a loaded footgun.

But I did absolutely love writing this code! So much fun. And now I’ve got another little thing brewing, also in Objective-C, coming soon-ish.

PS The website/blog generator app is called SalmonBay. I really don’t expect anyone else in the world to use it, and I expect no contributions, but it is available as open source. (I put it on Codeberg, for reasons.)

PPS SalmonBay does a clean build of this blog in under a second. 🎸

联系我们 contact @ memedata.com