Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

It's not philosophical, as it is code generation. The compiler doesn't see the #define. Which means the same source can be rebuilt with different defines and create hilarious undefined behavior.

This also means that there's no way to create a library that supports debug and not debug. And of course no ability for the user of the library to select this at runtime.

Yes, in the world of everything being compiled statically every single time (ala Google's monorepo) this can work, but code generation creates a HUGE number of gotchas, many of which are subtle.

> But I hope it clarifies that they're the same thing.

There're not, though.

void* is "the simplest option that comes to mind", but where a template solution is available, safer, and clearer, it's not "modern C++" to have code with void* all over the place.

"Easier" has nothing to do with it. There are many features in this fine library where the authors have put in effort to make it nicer, instead of just doing the easiest and quickest to implement.



> void* is "the simplest option that comes to mind", but where a template solution is available, safer, and clearer,

You're just playing silly semantics with "simplest" here. I meant that #define is genuinely the best overall solution to this particular problem, for the reasons I already gave. Whereas in void* vs templates, templates are genuinely the best overall solution.


#define makes things worse in almost all cases. It's extremely rare to see it done right, as opposed to just being the path of least resistance, that builds up tech debt where things break in hilarious ways.

I have seen many many well-intentioned "but surely this time it's the best solution", where no, it's just a time bomb.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: