3 ms·
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 amazi
by userbinator 11y ago
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 responsive as Windows on the same hardware --- it wasn't jerky/stuttering, just what I'd describe as "smooth but sluggish", and the binaries were noticeably larger, and I now wonder if this increased abstraction and complexity has anything to do with it.
For comparison, a similar Win32 app in plain C:
http://www.winprog.org/tutorial/simple_window.html http://www.winprog.org/tutorial/simple_window.html
X Windows app in plain C:
http://www.paulgriffiths.net/program/c/srcs/helloxsrc.html http://www.paulgriffiths.net/program/c/srcs/helloxsrc.html
...and just for fun, the same simple Win32 app from above in Assembly language:
http://win32assembly.programminghorizon.com/tut3.html http://win32assembly.programminghorizon.com/tut3.html
Looking at the code again, if I were forced to write an OS X app in plain C, there would be plenty of macro usage around objc_msgSend.
- barrkel 11y agoWindows 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.
- chillacy 11y agoThis 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 :)