Language change proposal
Joachim Durchholz
joachim.durchholz@REDACTED
Thu Oct 23 01:03:23 CEST 2003
Chris Pressey wrote:
> It's a good idea, but wouldn't it be easier to write code that works on
> different versions if it was done with macros, e.g.
>
> -ifdef(?ERLANG_5_3).
> % some code that uses bleeding-edge features here
> -else.
> -ifdef(?ERLANG_5_2).
> % some code that uses 5.2-isms here
> -else.
> % some code that is dangerously language-version-unspecific here
> -endif.
> -endif.
Most definitely *no*.
I have maintained C code that went like this; it was a nightmare. The
reason was that it offered too many opportunities for "clever writing"
like this:
if (normal condition) {
...
#ifdef VERSION = xxx
...
} else {
...
#else
...
} else {
...
#endif
...
}
You can't even properly do indentation...
However, there's one thing that /could/ be done: add an erlang_version
predicate that's guaranteed to be evaluated at compile time. Also, add
some rules about compile-time evaluation for expressions "known to be
constant" (these can be very simplicistic, look at the rules for Turbo
Pascal, for example).
With that, you can write stuff like (excuse the non-Erlang syntax here,
I've still not gotten around to making my ankles wet...)
if erlang_version = "5_3"
% some code that uses bleeding-edge features here
else
if erlang_version = "5_2"
% some code that uses 5.2-isms here
else
some code that is dangerously language-version-unspecific here
endif
endif
Regards,
Jo
More information about the erlang-questions
mailing list