Re: C callbacks with NSNotificationCenter?
Re: C callbacks with NSNotificationCenter?
- Subject: Re: C callbacks with NSNotificationCenter?
- From: Jens Alfke <email@hidden>
- Date: Wed, 07 Sep 2016 14:11:23 -0700
> On Sep 7, 2016, at 10:03 AM, Alastair Houghton <email@hidden> wrote:
>
> All of it can. Objective-C is just C with some syntactic sugar on top.
There’s a large amount of semantic sugar too, i.e. the runtime libraries. (If you think the runtime part must be trivial, go read some of Mike Ash’s posts about the implementation of objc_msgsend. That’s some of the most insanely optimized code I’ve ever seen.)
> Really. There’s nothing magic going on. (In fact, the original compilers were really just preprocessors that churned out C code.)
You can say this about nearly any compiler, though. Bjarne's original C++ compiler output C code too. The first-generation Go compiler output C code, but Go is absolutely not like sugary C. Most compilers used to output assembly code (nowadays Clang outputs LLVM bitcode), but it seems meaningless to say that those languages are “assembly with some syntactic sugar.”
But yes, you can use the Obj-C runtime API from C to do pretty much anything you can do in Obj-C, like calling methods and implementing classes. It’s just much, much messier, error-prone, and difficult to read compared to writing the damn code in Obj-C.
There’s no pride in refusing to switch languages. I abjured C++ a long time ago, but guess what, my current project is 99% C++ because that language best meets the performance and portability requirements. Next time maybe I’ll be using Swift, or Rust, or Pony. C is an ancient, primitive language and it’s not a good career move to refuse to move past it :)
—Jens
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden