[Oberon] Conditional compilation using IF const THEN
joerg.straube at iaeth.ch
Sun Aug 12 14:36:29 CEST 2018
The puristic me says: don't do it.
The pragmatic me says:
If I limit myself to something like
CONST debug = TRUE;
IF debug THEN Out.String("entry: "); Out.Ln(superDuper, 8); Out.Ln END;
Why not do it? During test phase "debug = TRUE". For customer shipment "debug = FALSE"
So, it's not really a different code I ship to customers and debug.
Another approach would be: Add compiler directives. Something like (* $if debug = TRUE *) and (* $endif *). But if a compiler doesn't implement these, your code might not compile at all.
The good thing with the "IF TRUE THEN Out.Ln END;" is: if your compiler doesn't optimize, it just generates superfluous code (your final obj gets larger) but doesn't harm.
Am 12.08.18, 14:17 schrieb "Oberon im Auftrag von Paul Reed" <oberon-bounces at lists.inf.ethz.ch im Auftrag von paulreed at paddedcell.com>:
>> A) add code to only parse. Something like a clever
> Generally though, I believe this would be optimization at the wrong
> place. The compiler is not not here to correct bad programming habits.
Agreed! The compiler is more valuable (not less!) because it sticks to
There is, after all, even in something as small as Project Oberon, a fast,
low-overhead, very fine-grained, type-safe module loader available...
The Linux kernel went with the module-loader approach eventually, not to
pay for code you're not using.
Also I believe that Prof. Wirth mentions somewhere a comment by Tony Hoare
that C-style conditional compilation of the form #if DEBUG / ... / #endif
is like learning to swim in a pool with flotation assistance and then
abandoning it the first time you swim in the sea! :)
It's certainly bad practice to be intentionally debugging a different
program than the one you intend to ship to customers, although it's often
Oberon at lists.inf.ethz.ch mailing list for ETH Oberon and related systems
More information about the Oberon