Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

MichaelS

macrumors newbie
Original poster
Dec 1, 2007
9
0
I'm a Windows developer interested in developing a (graphical) application in C++ to run on Mac OS X. I understand that Cocoa only works with Objective-C, so I would need to use Carbon. However, Apple has stated that it will not provide a 64-bit version of Carbon, at least not for the UI-portion, see http://www.carbondev.com/site/?page=64-bit+Carbon.

Now, my application doesn't need to be 64-bits at this point (although it would be nice). However, is it at least possible to write a 32-bit native C++ application on Mac OS X that has the same look-and-feel as a 64-bit application written in Objective-C?

I want my application to feel like a true, first-rate Macintosh application with a modern user-interface (and not look like some application written in the dark ages).

Also, what are my long-term prospects? When Apple releases e.g. Mac OS X 10.6, will it still be possible to write a state-of-the-art GUI-based application in C++ for it? Or is C++ simply the wrong language for Mac OS X programming?

Perhaps there is a chance that we will see 64-bit Carbon in Mac OS X 10.5.3 or something, what do people think?
 
For almost all applications there's no difference between 32 and 64 bit applications. Certainly none that's visible to the user. As for Carbon, it doesn't have all the native widgets, but most are there, and you can always make your own.
 
As for Carbon, it doesn't have all the native widgets, but most are there, and you can always make your own.

Well, I don't really want to get bogged down implementing my own widgets. The operating system is supposed to free me from that task. I just want to know if I have access to all widgets using C++.

What programming language do people use for theier Mac OS X development? Am I the only one interested in using C++?
 
Carbon widgets
 

Attachments

  • Bilde 5.png
    Bilde 5.png
    27.8 KB · Views: 21,990
  • Bilde 6.png
    Bilde 6.png
    21.2 KB · Views: 21,936
  • Bilde 7.png
    Bilde 7.png
    16 KB · Views: 21,910
  • Bilde 8.png
    Bilde 8.png
    22.4 KB · Views: 22,177
  • Bilde 9.png
    Bilde 9.png
    7.9 KB · Views: 21,883
Cocoa widgets
 

Attachments

  • Bilde 13.png
    Bilde 13.png
    25.3 KB · Views: 21,882
  • Bilde 12.png
    Bilde 12.png
    15.4 KB · Views: 21,846
  • Bilde 11.png
    Bilde 11.png
    28 KB · Views: 21,818
  • Bilde 10.png
    Bilde 10.png
    27.1 KB · Views: 21,862
  • Bilde 14.png
    Bilde 14.png
    14 KB · Views: 21,838
However, is it at least possible to write a 32-bit native C++ application on Mac OS X that has the same look-and-feel as a 64-bit application written in Objective-C?

It's possible. Interface Builder 3 makes it much better to create Carbon interfaces. But overall it'll take more work than Cocoa.

MichaelS said:
Perhaps there is a chance that we will see 64-bit Carbon in Mac OS X 10.5.3 or something, what do people think?

I highly doubt it. Don't count on it at all.

What programming language do people use for theier Mac OS X development? Am I the only one interested in using C++?

Objective-C is the "official" language.

Here's the low down: just because you're a C++ developer doesn't mean you should use Carbon on the Mac because it is available to you. By not including Carbon in the 64-bit goodness, Apple is essentially making Carbon obsolete in the next few years. They already stated they will not be adding as many features to it, mostly just bug fixes. The features go into Cocoa. Yes it will be available in the operating system for quite some time I imagine (probably through 10.6 and 10.7), but there aren't many apps anymore that use it (Adobe and Microsoft are the main ones).

If you're new to Mac programming (which you are), don't learn Carbon but learn Objective-C/Cocoa. It might be harder in the beginning, but it will pay off in the end.
 
My suggestion is to download yourself a copy of "The Objective C 2.0 Programming Language" from developer.apple.com and look into the section on "Objective-C++." This allows interoperability between C++ and Objective-C code, subject to certain rules. Assuming you're following a proper MVC division, you should be able to develop your model using C++ and then either put an Objective-C interface wrapper on top of your model or just bridge between languages directly in your controller. Depending on your needs you might be able to get by with a minimum of Objective-C and still have a proper Cocoa application.
 
You are not the only person using C++ in mac, i am too. But the best thing you can do is to use the graphical interface builder that comes with xcode... then add the .nib file to your program. 32 bit looks like 62 bit... no difference(visably).:apple:
 
Am I the only one who has thought on proposing learning Objective C++?

Since you are a C++ guy, you can use C++ in Cocoa, through Objective C++. Design the foundation of your application using C++, and design the UI using Objective C++. That way, you can use both languages, and Objective C as a wrapper to your C++ core.

I also do not recommend Carbon. It's just not that flexible and easy. Cocoa development is much faster than Carbon.
 
I would like to thank everybody for their help --- gekko513 for bothering to post screenshots, kainjow for answering all my basic questions, Gelfin and Soulstorm for pointing out the availability of Objective-C++, and unknown.exe for assuring me that I'm not alone :)

Based on your recommendations, I suppose I will take a look at Objective-C++ and ditch the idea of using Carbon. Not that I was reluctant to use Cocoa, it's just I knew it wasn't available to C++ programmers :(

I do find it annoying though that Objective-C is in effect the only language Apple actively supports for writing applications using Cocoa. They're really telling us programmers which language to use, and leave us no choice. Not that Objective-C is a bad language, but it's certainly unfamiliar to most programmers with a non-OS X background.

The reason I dispute this is that I would like to keep my application as platform-independent as possible, and having to use Objective-C makes this considerably harder, obviously. I don't think anybody writes software for e.g. Windows or Linux using Objective-C.

Since you are a C++ guy, you can use C++ in Cocoa, through Objective C++. Design the foundation of your application using C++, and design the UI using Objective C++. That way, you can use both languages, and Objective C as a wrapper to your C++ core.

Any sample code, or literature on this? (Apart from what Gelfin mentions.)
 
The reason I dispute this is that I would like to keep my application as platform-independent as possible, and having to use Objective-C makes this considerably harder, obviously. I don't think anybody writes software for e.g. Windows or Linux using Objective-C.

The other side of the coin is that they don't write applications for Windows or Linux using Carbon either. I'd suggest writing the majority of your application in pure, platform independent, C++ and write loosely coupled UI sections for each platform using whatever technology/toolset works best on that platform, so Cocoa/Obj-C for Mac OSX, .Net (maybe) for Windows, GTK+/KDE for Linux.
 
The other side of the coin is that they don't write applications for Windows or Linux using Carbon either. I'd suggest writing the majority of your application in pure, platform independent, C++ and write loosely coupled UI sections for each platform using whatever technology/toolset works best on that platform, so Cocoa/Obj-C for Mac OSX, .Net (maybe) for Windows, GTK+/KDE for Linux.

I appreciate your comment, but then on Windows at least you have a choice of programming language --- it's possible to write modern Windows apps using Basic, C, C++, Object Pascal (Delphi).

On Mac OS X you have to learn an entirely new language (with a really weird syntax if you're coming from C++).
 
Yes it [Carbon] will be available in the operating system for quite some time I imagine (probably through 10.6 and 10.7), but there aren't many apps anymore that use it (Adobe and Microsoft are the main ones).

So, what do you think Adobe and MS will do --- rewrite everything in Objective-C just to use Cocoa?
 
So, what do you think Adobe and MS will do --- rewrite everything in Objective-C just to use Cocoa?

I imagine they'll do what I suggested above: use their existing code base for all the complex and powerful functionality and just use Cocoa to provide a GUI over the top.
 
On Mac OS X you have to learn an entirely new language (with a really weird syntax if you're coming from C++).

Bite the bullet and give it an honest try. You may very well find you like it, and I know whereof I speak here. Objective-C is an interesting beast.

The not-so-dirty little secret of Objective-C is that really it's just plain old C with a fancy OO preprocessor and a runtime library. Theoretically you could cook up something functionally similar just using preprocessor macros. Basically it's an API that's unusually tightly coupled in presentation with the language, and the result is something pretty cool. You get the performance of a native compiled language with many of the spiffy runtime tricks of an interpreted language.

Think about it this way: You learn Win32 and ATL and MFC and .NET and the like to program on Windows and those won't benefit you in the least anywhere else. Picking up Objective-C on the Mac is not really all that different. You're just mentally tripping yourself up over a perceived difference in difficulty between learning an API and learning a language. Knowing C gets you 80% of the way there anyway. You'll spend WAY more time looking up interfaces for NS* than you will getting comfortable with Objective-C, I guarantee.

In fact, I'd say keeping the Mac in mind while developing on Windows has made me a better Windows developer. Keep the possibility of a Cocoa front end in mind, and you'll produce much cleaner code that doesn't contaminate basic functionality with platform-specific issues the way almost all Windows code written today inevitably does.

So, you know, eat your square brackets. They're good for you.
 
Think about it this way: You learn Win32 and ATL and MFC and .NET and the like to program on Windows and those won't benefit you in the least anywhere else. Picking up Objective-C on the Mac is not really all that different.

I would say picking up Cocoa framework really is no different. Objective-C is available on any platforms that support GCC (which means nearly every platform). Although you will most likely be missing many of the Apple libraries, GNUStep aims to provide some support.
 
Also, you can write Cocoa apps using Ruby and Python, and Java (although admittedly the Java-Cocoa bridge is deprecated), so you do in fact have a choice. It's not just Objective-C. I agree with the other posters that you should just learn ObjC. It's not that hard if you know C and if you're like me, you'll grow to really enjoy working in it. I'd rather write in ObjC than in any other language.
 
If you use C++, it's not that hard to write a portable program. If the core application is written entirely in pure, portable C++, then it's the GUI frontend that will change. And that won't be a problem in OS X, since you can wrap it up in ObjC style...
 
Thanks again to all (robbieduncan, Gelfin, eastcoastsurfer, mduser63, Soulstorm) for your help.

Now, does anybody here actually have experience writing Mac OS X apps the way outlined --- using straight C++ for the core parts and Objective-C/Cocoa to implement the user-interface --- or is this just the way you would go if you were in my situation?

Also, what literature would be useful to me? Apple recommends "Learning Cocoa with Objective-C", 2nd Edition, by James Duncan Davidson, and "Building Cocoa Applications: A Step by Step Guide" by Simson Garfinkel and Michael Mahoney. However, both books were published in 2002, so are presumably a bit dated by now.

Do people know "Cocoa Programming for Mac OS X", 2nd Edition, by Aaron Hillegass? It was published in May 2004, but is still said to be useful today (a 3rd edition is due out in spring 2008). Another text I found is "Programming in Objective-C" by Stephen Kochan, published in December 2003. Is this worth reading in your experience?

Any other books you would recommend?
 
Now, does anybody here actually have experience writing Mac OS X apps the way outlined --- using straight C++ for the core parts and Objective-C/Cocoa to implement the user-interface --- or is this just the way you would go if you were in my situation?

I'm in the scope-and-spec phase of a skunkworks project at my current employer along these lines, but I haven't got much specific advice to pass on at the moment. Most of what I'm doing right now is factoring the Windows-isms out of a legacy codebase, figuring out which parts I can jettison since OS X gives them to me for free, and charting out a proper Objective-C interface for it all.

The only thing that's making me crazy is the same thing that's always made me crazy about this code: it uses Boost. Not a fan.

Also, what literature would be useful to me? Apple recommends "Learning Cocoa with Objective-C", 2nd Edition, by James Duncan Davidson, and "Building Cocoa Applications: A Step by Step Guide" by Simson Garfinkel and Michael Mahoney. However, both books were published in 2002, so are presumably a bit dated by now.

Honestly, I've gotten by mostly with just the Apple documentation. I did actually flip through a lot of that "Learning Cocoa" book and twiddle with the examples. It's still helpful. Just be sure to search the threads here before posting the inevitable "OMG WHERE'S THE CLASS TAB" post. I swear there must have been fifty such threads started within the last month. It should probably be a sticky topic or something.

You won't see a lot of the newer stuff like Core Data and bindings, but again, Apple documents those fairly well.

Do people know "Cocoa Programming for Mac OS X", 2nd Edition, by Aaron Hillegass? It was published in May 2004, but is still said to be useful today (a 3rd edition is due out in spring 2008). Another text I found is "Programming in Objective-C" by Stephen Kochan, published in December 2003. Is this worth reading in your experience?

I don't own Hillegass, but it seems to be the standard, sort of to Mac programming what Petzold is on the Windows side. It's highly recommended. I'll probably pick up a copy once the 3rd ed. is released. I honestly wouldn't recommend getting a book that's just Objective-C. If you know C, the Apple-supplied Obj-C language spec is more than enough to get you rolling. It's actually quite a bit more readable than, say, Stroustrup.
 
Gelfin, thanks for your comments!

I just found out about this book "Cross-Platform Development in C++" by Syd Logan to be released later this month. The website is http://www.crossplatformbook.com/. Maybe that's also a book worth buying when it's available? At least it does the Mac OS X part using Cocoa, so some amount of Objective-C must also be covered.
 
Gelfin, thanks for your comments!

I just found out about this book "Cross-Platform Development in C++" by Syd Logan to be released later this month. The website is http://www.crossplatformbook.com/. Maybe that's also a book worth buying when it's available? At least it does the Mac OS X part using Cocoa, so some amount of Objective-C must also be covered.

Funny, I just found out about that book myself. You know, just now when you posted it. Always hard to know for sure, but it looks like it could be a fairly excellent sort of book. And the timing couldn't be better, considering how hard it is for folks to buy Christmas presents for me. ;)

From the description, it may not cover the Cocoa front all that much, though. Mozilla doesn't use the standard Cocoa UI development model. They took a much harder approach to cross-platform UI, by developing their own toolkit that works across supported platforms. It's also why Mozilla projects don't usually look quite exactly like a normal Mac application. If you need to write something cross-platform and have access to such a general UI framework, it's definitely an option to evaluate. At this point not many people will have the frame of reference to help you decide whether it's the best option. If you find out, come back and tell us. :)
 
Might I suggest Trolltech's Qt for Mac? The latest version is 4.3.2

I use it professionally on Linux, and have installed the Mac version at home (haven't used it much there yet).
 
If you decide to go with ObjC and/or Cocoa, the two books you mentioned, "Programming in Objective-C" by Stephen Kochan and "Cocoa Programming for Mac OS X" by Aaron Hillegass are IMO the way to go. They're both sort of the "standard" for new Cocoa programmers. Kochan's book in particular is one of the best technical books I've ever read.
 
If you decide to go with ObjC and/or Cocoa, the two books you mentioned, "Programming in Objective-C" by Stephen Kochan and "Cocoa Programming for Mac OS X" by Aaron Hillegass are IMO the way to go. They're both sort of the "standard" for new Cocoa programmers. Kochan's book in particular is one of the best technical books I've ever read.

Yes I definately agree, also it is a good idea to wrap C++ w/ cocoa/C. All of the above suggestions are superb. But I have recently stumbled upon a little chapter from hevean in the C++ Book for Dummies that addresses your problem down to a word. I would definately pick it up. Also, stick w/ C++... it's a better language than most others and easier to learn as an intermediate programmer.:apple:
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.