Live data from Hacker News

OS X app in plain C

github.com

121–130 of 157 posts

Re: OS X app in plain C

#121
post #26

Earlier quoted context omitted.

Windows, X11 and Gtk would argue with you.

Windows is written in C++ mostly. As for X11 and Gtk, well, I argue with THEM.

Unless something has changed drastically since when I was at MS, the Windows kernel and the major OS DLLs is pretty much pure C. The GUI/window manager are more C++.

Even Word and Excel were still C (although Office shared much C++ code in a common DLL)

Gotta love legacy code from the 1980s/1990s.

Re: OS X app in plain C

#122

I'm sure the Windows version would be just as bad. Most of the useful parts of the Windows API don't have a C interface, so you have to use COM, which essentially means editing vtable-like structures by hand. https://en.wikipedia.org/wiki/Component_Object_Model

You wouldn't have to use COM for this at all. You could use the Win32 API directly, which is a C API and would be much less code. In fact I'll link a comment from above that shows this: https://news.ycombinator.com/item?id=11641545

Re: OS X app in plain C

#123

As someone who has done a lot of Win32 programming in plain C, I can recognise some common patterns like an event loop and window creation, but it's quite amazing how much extra "cruft" there is just to deal with what appears to be the contortions of OOP'ing everything. All those string constants are rather surprising too. The interesting thing is, the few times I've had to use a Mac the GUI didn't feel quite as resp…

Windows is effectively already an OO system; you "override" methods (message codes) in your window procedure, with the base implementation provided by the default window procedure. Windows even uses the terminology of window classes to describe the behaviour of window instances.

Personally, I'd blame UI latency more on a deeper composition stack and rendering sophistication rather than object orientation. Unless you're using late bound method calls for pixel-level drawing primitives, they shouldn't be a significant percentage of the event dispatch loop that turns input into visual results.

Re: OS X app in plain C

#124

I'm sure the Windows version would be just as bad. Most of the useful parts of the Windows API don't have a C interface, so you have to use COM, which essentially means editing vtable-like structures by hand. https://en.wikipedia.org/wiki/Component_Object_Model

I've been programming Windows GUI apps for over a decade. Most of the Windows API, i.e. Win32, is not COM.

I have also used COM from C, and while it's not as pleasant as the pure Win32 API, it doesn't involve the massive amounts of function pointer casting shown here. vtables are involved but they can be defined as C structures, whereas this example seems to show objc_msgSend() returning a very large number of different possible function pointer types.

Re: OS X app in plain C

#126
post #5

There was a thread the other day where people were talking about languages that were easily interoperable with the "C ABI" (although there is no such thing). Languages listed included C++, Rust, and maybe a few others--but no mention of Objective-C. The ability to use a high-level, dynamic language (ObjC), C, and even inline assembly in a single source file is unique to Objective-C (at least among the "mainstream" la…

I'm going to miss Objective C terribly. It is, hands down, still my favorite language (and ecosystem). It's interoperability with C got me into C. It was insanely powerful and fun. I know not many people agree with me. I liked the square braces and crazy long function names. I know Swift is decent... It's not the same. Oh well. Lamenting my path to software engineering doesn't mean much for anyone else. But I really…

[deleted]

Re: OS X app in plain C

#127

Earlier quoted context omitted.

> Still Objective-C objects have underlying C functions that are being called whenever you try to call a method or anything on an Objective-C object. The same goes for C++ or Swift. Getting the function pointer for a method can be involved, but all functions adhere to the C ABI.

What C ABI? Can you point me to the spec?

I don't believe C standardizes the ABI across all OS/hardware combinations. But some OS/hardware combinations are standardized; for example, there's the AMD64 ABI[1], which I think just about every operating system that runs on amd64 uses … except Windows.

[1]: http://www.x86-64.org/documentation/abi.pdf

Re: OS X app in plain C

#128
post #55

Earlier quoted context omitted.

To put it another way: C doesn't have an ABI; C has an API (or a wire protocol, if you prefer.) The abstraction layer of C doesn't exist between the machine-architecture and the C compiler; rather, the abstraction layer of C exists between the C compiler and the user, and takes the form of uncompiled C source code. The design of C is predicated on an approach to portability that involves shipping source code , not bi…

What, like C as a shell script? Gott in Himmel!

How about an interactive C++ interpreter: https://root.cern.ch/cling

Also it's Gott im Himmel ;-) (unless it's a reference I didn't get)

Re: OS X app in plain C

#129

As someone who has done a lot of Win32 programming in plain C, I can recognise some common patterns like an event loop and window creation, but it's quite amazing how much extra "cruft" there is just to deal with what appears to be the contortions of OOP'ing everything. All those string constants are rather surprising too. The interesting thing is, the few times I've had to use a Mac the GUI didn't feel quite as resp…

This example is extremely contrived, of course it's going to be a nightmare in C. GUI latency probably has little to do with the overhead of objC message sending and more to do with tuning how things respond for UX purposes. For instance it's well known among gamers that on OSX the mouse has acceleration which makes it smother but less responsive in gaming. I wouldn't be surprised if this carried over to scrolling, animations, etc.

> If I were forced to write an OS X app in plain C, there would be plenty of macro usage around objc_msgSend

You will have re-invented the early versions of Objective C which were all done in the preprocessor :)

Re: OS X app in plain C

#130

Earlier quoted context omitted.

C was not designed to create gui's. So its a feat of accomplishment as opening a bottle with your teeth.

Windows, X11 and Gtk would argue with you.

There's Carbon as well, which was replaced by Cocoa. And as of 4 years ago (and I suspect today as well) there are still some things which you could only do in the Carbon's C APIs, so lots of CoreFoundation types which you can bridge directly from their objective C equivalents. Pretty neat stuff how well the backwards compatibility works.
Post reply on HN