Repository navigation
Coding Styles
kweicht edited this page Jun 7, 2012
·
3 revisions
Each system can be its own class (class CGraphicsDevice) with member functions that work on it. This would be the most "traditional" way of doing it.
Example:
class GraphicsDevice
{
GraphicsDevice(void* window);
~GraphicsDevice(void);
Draw(void* mesh_data, void* index_data);
};
- Most normal
- Logically the easiest to think about
- Perhaps the least verbose
- When abusing C++ features, many things (such as interfacing with Lua) can be greatly simplified from the callers standpoint
- Too easy to over-engineer problems because C++ lets you
- Abusing simple C++ features (constructors, templates, etc)
- C++ can be a pain to work with when doing cross-platform support
- When abusing C++ features, the code can become damn-near unreadable
Example:
typedef struct lae_graphics_device_t lae_graphics_device_t;
lae_graphics_device_t* lae_graphics_create(void* window);
void lae_graphics_destroy(lae_graphics_device_t* device);
void lae_graphics_draw(lae_graphics_device_t* device, void* mesh_data, void* index_data);
- Very simple API
- Logically very easy to see what belongs where
- Easier to focus on the actual problem you're trying to solve, rather than how to code it
- Much greater cross-platform support
- Very verbose
- Untraditional
- None of the convenient C++ features
This interface would use C-like functions, but wrapped up in C++ namespaces. This would give it the C++ features, but force the functions to be written in a C-like way.
Example:
namespace Graphics
{
struct Device;
Device* Create(void* window);
void Destroy(Device* device);
void Draw(Device* device, void* mesh_data, void* index_data);
}
- Still C++
- Very C-like
- Still C++, so cross platform is still a bitch
- Very easy to fall into C++ traps