Hacker News new | past | comments | ask | show | jobs | submit login

Let DEBUG be a compile time constant, and the optimizer will remove the check.

What do you feel is gained with "const int DEBUG" over "#define DEBUG"? While most compilers will do what you say most of the time, I haven't encountered a significant downside to the macro approach.

I also like that I can have a makefile where "make debug" adds "-DDEBUG" to the compiler command line and appends "_debug" to the executable name. With the const approach, is there an easy way to automatically generate both debug and production executables?




One advantage is that the protected code will be syntax and typechecked even if it is "compiled" out. That will make it less likely to bitrot.


Yeah it's hard to keep exponentially many code configurations that may compile together.

It's hard to support in an IDE. Where a variable works nicely


I guess the argument is orthogonality. It is a desirable property in programming languages to not have overlapping features, because people will always be confused about when to use which (the classic example being pointers vs. references in C++).




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

Search: