Re: Advice on converting this C++ code to Objective-C
Re: Advice on converting this C++ code to Objective-C
- Subject: Re: Advice on converting this C++ code to Objective-C
- From: Jean-Denis MUYS <email@hidden>
- Date: Thu, 03 Nov 2011 10:00:11 +0000
- Thread-topic: Advice on converting this C++ code to Objective-C
On 3 nov. 2011, at 10:29, Dave wrote:
Can anyone offer any ideas or suggestions on the best course of action to convert this?
What is the purpose of converting to begin with? The first course of action to consider is to keep using Objective-C++. I have used C++ quite a bit in a previous life, and now that I work with Objective-C I tend to keep away from C++ and its more esoteric features,
but from times to times, C++ is helpful. Overloading operators, can - if used wisely - reduce complexity. C++ can also help in very specific instances regarding performance and abstraction. I once managed to accelerate a processor intensive routine of an app
by a significant factor, going from Objective-C classes to C structs*. Except I went to non-virtual C++ classes instead. This helped me keep the Object-Oriented encapsulation while still reaping the benefit of pure-C optimization.
My initial idea is to make a corresponding Objective-C for "CGraphics"
and then change all references CGraphics
to use the new class.
Does this sound like a good idea?
Well, yes.
Once that was done, I'd have the CMatrix, CVector2 and CVector3 to remaining in C++, which I want gone!!!
I don't see the point of the exercise if you don't also convert those classes.
Also one thing that is going to make it difficult is that there operator overrides in operation which will mean expanding out loads of code in
Objective-C.
You will need to convert from operator overloads to method calls. You will loose some readability, but regain some thanks to named parameters. The result is going to be a lot more verbose, but so what?
So I could either convert them to Objective-C but it strikes me that CoreGraphics has all this built in.
Would it be better to use this? I'm a bit concerned that the results won't be the same and also I'm not sure what to do for the best.
I would convert all classes one for one. When this is working, I might want to refactor some of those classes, for example to get rid of some if they are too thin layers above OS X frameworks. Or not, if they don't have any bad impact on the app behavior.
Jean-Denis
* don't conclude that Objective-C is much slower than C (or C++). my example is a very special case, and is worth mentioning only to the extent that a limited subset of C++ is indeed a better C than C.
|
_______________________________________________
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