example of C++:
world.h
struct World { // ... fields ... void update(const Update_Context& context); private: void update_aims(const Update_Context& context); };
world.cpp
void World::update(const Update_Context& context) { update_aims(context); } void World::update_aims(const Update_Context& context) { // ... }
2025-02-28 example of C++ without Classes:
world.h
struct World { // ... fields ... }; void update(World& world, const Update_Context& context);
world.cpp
static void update_aims(World& world, const Update_Context& context) { // ... } void update(World& world, const Update_Context& context) { update_aims(world, context); // ... }
2025-02-28 suddenly, the publicly available part of
world.h
has gotten smaller—there’s one method less. the implementation detailupdate_aims
does not leak into the header; we don’t have to update the signature in two places if we ever want to change it, and it does not cause a recompilation if we edit it.2025-02-28 in my own code, outside this contrived example, I also put functions related to a data structure in a namespace—in this case,
update(World&, const Update_Context&)
would beworld::update(World&, const Update_Context&)
. this is purely a stylistic preference—I like the extra explicitness over leaning on overloads.2025-02-28