Coding Styles - 10n1/LAE GitHub Wiki

Coding Style

C++

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);
};

Pros

  • 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

Cons

  • 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

C

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);

Pros

  • 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

Cons

  • Very verbose
  • Untraditional
  • None of the convenient C++ features

C-like C++

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);
}

Pros

  • Still C++
  • Very C-like

Cons

  • Still C++, so cross platform is still a bitch
  • Very easy to fall into C++ traps