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

How D decides it is if the grammar says its a constant-expression, whatever makes up the constant-expression gets evaluated at compile time - functions and all. For example,

    int square(int x) { return x * x; }

    static assert(square(3) == 9);
This allows one to write unit tests that are checked at compile time, whereas:

    int main() { assert(square(3) == 9); }
is always a runtime check.

Compile time unit testing is a significant win:

1. it's always more productive to find problems at compile time rather than run time

2. it isn't necessary to conditionally turn off compilation of the tests for the release build

3. you can't forget to run the tests before shipping




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

Search: