Structure of platform specific vs non platform specific code

Igor via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon May 8 14:16:53 PDT 2017


Hi,

I am following Casey Muratori's Handmade Hero and writing it in 
DLang. I got to Day 011: The Basics of Platform API Design where 
Casey explains the best way to structure platform specific vs 
non-platform specific code but his method cannot work in DLang 
since it uses modules and I am wondering what would be the best 
way to achieve the same in DLang.

His way is to have these files:
- platform.cpp (includes game.cpp directly, not game.h)
- game.h (declares non-platform specific data types for 
communicating with platform layer and both game functions that 
platform layer needs to call and platform functions that game 
needs to call)
- game.cpp (includes game.h and defines declared game functions)

This scheme makes preprocessor actually merge all files into one 
but logically game.* files see nothing that is platform specific.

The best idea for DLang I have is to separate platform into two 
modules:

- platform.d (contains only code that needs to call into game 
code so it imports game.d)
- platformServices.d (contains only code that game needs to call 
but wrapped in a common abstraction layer so game.d imports it)


More information about the Digitalmars-d-learn mailing list