Re: Programming Languages
Re: Programming Languages
- Subject: Re: Programming Languages
- From: Tom Davie <email@hidden>
- Date: Sat, 06 Apr 2013 19:33:34 +0100
On 6 Apr 2013, at 18:51, Harmony Neil <email@hidden> wrote:
> Hellow,
> is it possible to program mac and/or iPhone apps using the c++ programming language? I thought it was, but everything I've seen in xcode so far is mainly concentrating on objective c. Also, can I compile apps with g++ in the terminal and run the executables on my iPhone or computer to test them? It seems a lot easier than having xcode putting a tonne of code there that I didn't write in the first place.
> Thanks for any suggestions,
> Harmony.
Hi Harmony,
There's several points to this.
1) Yes, you can use C++ to your hearts content. Xcode fully supports it (though not quite all of C++11 yet – who does?)
2) Mac "apps" can be entirely C++ code, but this will somewhat limit you (because of 3)
3) The API for creating windows and views on both iOS and Mac OS (called Cocoa, or Cocoa Touch) is only accessible via Objective-C. You will need to write at least some Objective-C code if you want to display a user interface.
4) You can also use a language called Objective-C++. This is effectively Objective-C, but built on C++ instead of C. It does however introduce a bunch of extra corner cases that you need to be careful about. Because of that, the best approach (if you want to use C++) tends to be to write your view code in pure Objective-C, your model, and actual application logic in C++, and a thin wrapper around your model in objective-C++ that allows the obj-c code to talk to it (with a liberal application of preprocessor magic to make sure that the obj-c and C++ code only ever sees the things it should see).
5) The GNU toolchain on OS X is slowly but surely disappearing. What's left is also rather ancient. If you want to compile C++ code on Mac OS, you're better off using clang++ than g++. This has a bunch of other advantages (produces faster code, runs faster, produces *way* better error messages, handles more of C++11, etc)
6) For all of this, if you're writing Mac or iOS applications, use Xcode. Really. Even if you use an external editor, Xcode is all set up to deal with building in a much more straightforward way than the hoops you would need to jump through if you tried to use auto tools or Cmake.
7) Finally, with all of this in mind, and all of the ways you can push things and do stuff your own way… Don't fight things. Fighting the way the APIs and tools are set up is a sure fire way to get yourself a whole world of pain on any platform. Learn Objective-C (it's only a day or two's learning for an experienced coder, and it's a fairly nice language, even if it does lack some features, like a fair level of type safety, and parametric polymorphism); Learn to use Xcode; Learn to use Interface Builder (really, no matter how much your programmers instinct tells you to write code, IB saves enormous amounts of time); basically… Try it the "right" way before you figure out what the right amount of "wrong" way is.
Thanks
Tom Davie
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden