debug

Get tol learn about the debug feature of conditional compilation in D.

We'll cover the following

debug is useful during program development. The expressions and statements that are marked as debug are compiled into the program only when the -debug compiler switch is enabled:

debug a_conditionally_compiled_expression; 

debug {
    // ... conditionally compiled code ...
} else {
    // ... code that is compiled otherwise ...
}

The else clause is optional.

Both the single expression and the code block above are compiled only when the -debug compiler switch is enabled. We have been adding statements into the programs, which printed messages like “adding,” “subtracting,” etc., to the output. Such messages (aka logs and log messages) are helpful for finding errors by visualizing the steps that are taken by the program.

Remember the binarySearch() function from the templates chapter. The following version of the function is intentionally incorrect:

Get hands-on with 1200+ tech skills courses.