Sane API design (AKA C's #ifdef hell)

Richard (Rikki) Andrew Cattermole richard at cattermole.co.nz
Sat Apr 18 11:22:44 UTC 2026


On 18/04/2026 10:13 PM, libxmoc wrote:
> I'm not a fan of this mindset, both are valuable, besides, this is 
> exactly the problem. When the idiomatic answer to a problem is hack.., 
> we need to kill this workaround culture and give people something that 
> actually works.
> 
> dmd -define:GL=43
> 
> |module gl; import core.config; // dmd would build this on demand at 
> import time void draw() { static if (define.GL >= 33) { // use vao } 
> else { // fallback old opengl } } |
> 
> This is just a random example, don't view this as a feature request.

OpenGL is a horrible example for versioning.

A single executable could support 4.5, 3.3, 2 and pick at runtime.

You load the OpenGL bindings twice, once for first context, then once 
you know what you need and created the second context you load again.

I have wanted a config file available by dub automatically with such 
metadata. It would need to be per-binary.

The main issue is you're going to run into is symbol conflict if you 
compile it in multiple times.



More information about the Digitalmars-d mailing list