version(number) is completely useless

Andrey Zherikov andrey.zherikov at gmail.com
Wed Jul 20 16:23:06 UTC 2022


Don't get me wrong, I understand why Walter doesn't want to bring 
`#define`/`#ifdef`/`#if`/`#undef` into D and I agree with him. 
Let's take a look at them:

`#undef`:
There is no such a thing in D - you can't undef a symbol. This 
effectively removes the mess referenced in this thread (at least 
one of its flavor).

`#define`:
It's used to define macroses and compile-time constants. D offers 
template engine for the former and enums for the latter. They 
work perfectly except that I'm not able to set compile-time 
constants from compiler command line (as I mentioned earlier).

`#ifdef`/`#if`:
These are used for conditional compilation. D offers `version` 
and `static if` for these. To be precise: `#ifdef` == `version` 
and `#if` == `static if`.
Since `version` checks whether a symbol is defined only and this 
can be done with `static if(is(typeof(VERSION_ID)))`, the latter 
has all the features that `version` has making it useless IMHO.


There is also another `#ifdef` mess allowed in C:
```c
void func(
#ifdef FOO_INT_PARAM
     int param
#else
     double param
#endif
   )
```

This is not allowed in D due to its syntax - you can use `static 
if` inside function definition. This is also great (IMHO) 
decision.


More information about the Digitalmars-d mailing list