Live data from Hacker News

OS X app in plain C

github.com

141–150 of 157 posts

Re: OS X app in plain C

#141
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…

Is objective-C going away?

Also, are there any particular resources that you would recommend for beginners? I'm looking forward to reading this article since it might expose the low-level details of how, say, message passing works under the hood. Most of the guides are a bit too "beginner-oriented"; I'd love to find something that pulls up the carpets to reveal all the infrastructure underneath.

Re: OS X app in plain C

#142

Earlier quoted context omitted.

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

Yeah, but that's a bit of a long bow... That's not a C ABI :-)

Re: OS X app in plain C

#143

> For some reason if we run the app from command line than menu is not accesible by mouse at first time This happens with Qt apps on OS X, as well, and it drives me bonkers. If you launch from the command line you have to command tab away and back for the menu to work

Strangely this happens on my cocoa app too... but it hasn't always been the case and I've had this thing for about 5 years now, so I suspect that somewhere, something got messed up.

It started for me around on the Mountain Lion to Mavericks upgrade, so whatever changed then.

Re: OS X app in plain C

#144
post #99

sorry, but mediocre at best, full of mistakes at worst. i'm sure it was a good exercise in learning objective-c but this is not an amazing achievement. i'd expect much better from someone competent reading the god awful docs and reverse engineering by inspection. don't give up though. doing things like this over and over, especially in the face of nay saying arses like me, is what makes great programmers. :)

As a beginner to Objective-C, I found reading the source here highly informative, because it gives you a rare peek at the actual machinery underneath everything that's going on.

Re: OS X app in plain C

#145
post #141

Earlier quoted context omitted.

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…

Is objective-C going away? Also, are there any particular resources that you would recommend for beginners? I'm looking forward to reading this article since it might expose the low-level details of how, say, message passing works under the hood. Most of the guides are a bit too "beginner-oriented"; I'd love to find something that pulls up the carpets to reveal all the infrastructure underneath.

Swift is the future Apple is pushing to developers. There is an insane amount of Objective C in the world for sure, so it's not going away completely, but I expect more new work will choose Swift, and eventually Objective C will be relegated to Apple devs working on OS X itself, plus legacy apps.

But maybe I'm wrong, and I'd be happy if I were.

Re: OS X app in plain C

#146

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

The two replies to my comment both need a response, so I'll make this a sibling.

Looks like I was wrong, and I was working harder when I wrote Windows C programs than I needed to. The Windows API documentation is sort of confusing and I got the impression that only the CRT functions have a C interface.

Re: OS X app in plain C

#147
post #141

Earlier quoted context omitted.

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…

Is objective-C going away? Also, are there any particular resources that you would recommend for beginners? I'm looking forward to reading this article since it might expose the low-level details of how, say, message passing works under the hood. Most of the guides are a bit too "beginner-oriented"; I'd love to find something that pulls up the carpets to reveal all the infrastructure underneath.

If you are already familiar with high-level Objective-C, I would recommend looking at the headers for the language runtime. All of the inner workings are exposed as C functions you can play with. Also take a look at Mike Ash's blog, which dives into a lot of details: https://mikeash.com/pyblog/?tag=objectivec

Also: http://www.sealiesoftware.com/blog/archive/index.html

Re: OS X app in plain C

#148

Earlier quoted context omitted.

Objective-C was the major inspiration for Java - you'll notice how little it looks like C++ - and therefore C# and co, so it's been very influential ever since the 90s. It's not worth listening to anyone who dislikes Obj-C just because of the [] syntax, which doesn't matter after the first 48 hours.

This about mirrors my opinions about Objective-C. http://twistedoakstudios.com/blog/Post8237_a-years-worth-of-...

> Lastly, neither has generic types.

Not true anymore; ObjC has generics with type erasure. (But not all the cases can be exported to Swift.)

> Instead, Objective-C has nil, which is like null except it won’t stop the program when you accidentally use it.

That's… not quite right… but I guess he has the visible effects down. Anyway, ObjC has nullability annotations now for this.

> For example, in Objective-C many objects have both a “core foundation” form and a “new style” “NeXTSTEP” form

This is not legacy baggage, it's an intentional C bridge.

> This is justified by conventions strongly favoring you not catching exceptions, and apparently the speed benefits are non-negligible, but it still blows my mind that Apple has their language default to incorrect behavior.

He shouldn't use ARC+exceptions, because Cocoa itself is not exception-safe. Just quit the app if you get one.

Re: OS X app in plain C

#149
post #10

Earlier quoted context omitted.

Really? I don't write systems software but it seems most here would not recommend writing in C/C++ unless it's absolutely the best choice.

I don't know who you've been talking to, but that's ridiculous. C++ is one of the most widely-used languages for writing native apps for any OS. Adobe products, Chrome, anything built with Qt, even the Swift language itself, all made in C++.

> Adobe products

Adobe products have codebases going back decades, of course they are written in C/C++. Furthermore most Adobe apps have fairly advanced processing needs that your run-of-the-mill CRUD GUI does not.

> anything built with Qt

Qt isn't even stock C++, they had to hack a meta-compiler on top of C++ to effectively serve the needs of their GUI system.

> even the Swift language itself

By this logic, thousands of GUI apps are written in x86 assembly.

Between C#, Objective-C, Swift, JS+Electron, Mono, and many other mature, high-level frameworks that don't trash memory at the slightest provocation, youd need some very good reasons to use C or C++ for a GUI app these days.

Re: OS X app in plain C

#150
post #10

Earlier quoted context omitted.

Really? I don't write systems software but it seems most here would not recommend writing in C/C++ unless it's absolutely the best choice.

Why recommend Objective-C over C/C++ though? It's more or less subject to the same "pitfalls" that go against C, PLUS it is a syntactical nightmare. [whatTheHell:is this:shit]; Is ARC really that much of a savior here? At least method calls get resolved at compile time.

> It's more or less subject to the same "pitfalls" that go against C

Only if you write C code in Objective-C.

> PLUS it is a syntactical nightmare. [whatTheHell:is this:shit];

Honestly, get over it. This is largely a surface-level detail that makes no difference once youve used the language for more than a week. I take it you have similar complaints against Ruby, Python, Lisp, or any other language that dares to break ranks with the C++/Java syntax idiom.

> Is ARC really that much of a savior here?

Yes, manual memory management is one of the main things that C/C++ programmers seem to consistently screw up.

Post reply on HN