I'm currently working on a game logic engine that I'm developing in c++ because that is what was taught to me years ago, and that's what I feel comfortable using. I feel learning the ins and outs of a different language would just be a road block right now. I'm just looking to get a working logic engine down on paper so to speak, so I can bring it to other coders for further development. My goal is to port the game and skin it with a gui as an iphone, android, and flash-based app (or possibly java, if flash porting becomes a problem).
From what I can gather iphone development will take place with an obj. c base, and android will use a java base. I'm not sure what flash uses, but since android will use a java code-base, it may end up making more sense to just port the game to a common point in java, and then branch off for an android app and a cross-platform java app (rather than going the flash route).
Either way, I don't know very much at all about obj. c, java, or flash, so I'm looking for pointers to keep my c++ code-base as portable as possible. For the most part I'm using elements that are (I believe) common to all languages. Definition syntax may vary, but things like variables, constants, arrays, classes/structs, objects, functions... these are all common factors in (modern) programming (at least I hope so).
I know that using an object oriented approach is best for portability, so that's what I have been doing. There are no global variables or functions, everything is defined as structs/classes and values are passed from objects rather than referencing a global variable.
So basically I'm looking for what features of c++ should I avoid to allow easy portability? The basics I'm sure will work, but what of more advanced features, like for example:
1. Pointers and references and working with memory addresses (I'm vaguely aware that these don't have an analog in java)?
2. Default constructors for objects?
3. Overloading operators? (I'm fairly sure this is c++ exclusive)
4. Overloading functions to respond to different data types?
5. Virtual functions and abstract classes?
6. Ability to use maps (specifically), and if not, alternatives that act like a dynamic array using keys?
7. Ability to assign a derived object to a base object using a simple operator (hopefully "="), without defining an overload function (with slicing)?
8. Ability to pass a derived object as a parameter to a function expecting a base object (with slicing)?
9. Ability to pass a derived object as a parameter to a function expecting a base object, without slicing, using pointer-to-base and virtual functions?
10. Ability to define a base class function that takes a parameter of a derived class (fully without slicing), by making a derived class definition prototype prior to the base class definition.
11. Any other polymorphic or general things to consider?
Thanks for the help, this site has been an amazing resource.
Pointers should not be used in your case because only C# supports them aside from C and C++ that I know of and even then they are handled poorly and should be avoided.
C++ is extremely Object Oriented friendly but unless you get seriously complex with you hierarchies you shouldn't have any trouble converting them to Java. You will find out soon enough how much control C++ gives you in that matter, though. Hint - C++ gives an assload of control.
I do not have much experience in Actionscript but what I have seen I can tell that it is much more simple than full on programming languages like C++, Java, and C# so that will definitely be your delimiting factor.
The derived to base object relationships, I can't confidently comment on but I know most scenarios are allowed in C# which was modeled after Java so it should be allowed there too.
I certainly don't need pointers, as they add a layer of complexity I've come to understand, but don't necessarily see the need for. From what I can tell, for my purposes, they would simply give a performance increase by copying parameters as reference rather than value, at the cost of increased complexity and lower portability.
Up until this point I haven't used, or felt the need for them. Certain problems have come up that could have been solved with pointers, but I have always found an alternative (cause in the back of my mind I knew about the java compatibility issue, which you have now confirmed).
On a separate note, I have yet to confirm... are default constructors, and overloading functions with different types c++ specific? Should I write an initialization function instead of using a default constructor? And use a different work around rather than overloading functions?
> what features of c++ should I avoid to allow easy portability?
If you are thinking of portability in terms of line by line translation of the source code, the situation is desperate.
Avoid: copy constructors, assignment operators, multiple inheritance, private and protected inheritance, overload resolution based on conversions, any form of metaprogramming, anything more than the most trivial forms of compile time polymorphism, RAII to manage resources (no constructor acquiring a resource and destruction releasing it, but C-style sandwich functions - open/close, get_lock/release_lock etc.), pointers (use std::shared_ptr<> instead), references (use std::reference_wrapper<> if you have to), separate compilation model (do not separate the interface of a class from its implementation - put everything inline in a header file) - the list goes on. You won't have much of C++ left.
> I feel learning the ins and outs of a different language would just be a road block right now.
Not really. If you know C++, you should be able to learn Java (the language) over a weekend and start writing productive code immediately. Learning the language library will take a bit more time - say a week or so. And then write your code in Java - it is quite easy to port Java to C++ or objective C.