TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Ask HN: Cocoa: Why not use delegate callbacks less?

1 点作者 mman大约 14 年前
Callbacks are nasty! This is objectively true (ahee!).<p>Callbacks make sense for UI widgets. In this case, the programmer is not the one generating the event, the user is.<p>But when the programmer is initiating some high-latency request with a completion event, why not just expose synchronous functionality and let it be composed and made asynchronous using blocks?<p>The control flow for chaining delegate callback based class functionality is so disgusting! Think about it. You send a message. Later, control flow continues at some point which, in the standard cocoa delegate pattern, i can only discern by looking at your documentation or headers. In addition, if there are multiple points where the initial message might have been sent, i may even have to DEMULTIPLEX using some state i have kept on the initial message send points to determine which is which. At this point, i might even send ANOTHER message with a callback, which i also have to track through documentation and track with my eyeballs through some crappy ad-hoc demultiplexing if statement because there is no general language facility for handling this problem. Also, you may or may not be able to determine the context of the send using just the method parameters. YUCK!<p>Finally, my question: Don't you agree? Why don't we prefer to expose synchronous functionality when possible and let the user compose it using blocks and either operation queues or grand-central dispatch? In this way, not only is the control flow actually parseable, but the user has more control over parallelism. Keep your callbacks for status updates and this sort of thing.

暂无评论

暂无评论