Erlang/OTP R10B-10 has been released

Matthias Lang matthias@REDACTED
Tue Mar 21 08:54:50 CET 2006


Mats Cronqvist writes:

 > i do believe Richard A. O'Keefe was correct in writing, "There
 > really isn't anything that can be done with the [preprocessor]
 > that could not be done better without it".

Once upon a time, I wrote constants like this:

  pi() -> 3.0.   %% US-version

I was then a bit surprised that you have to turn inlining on to really
make the function disappear. Why is the default inlining policy so
conservative?

---

Another thing. A major use of the preprocessor is conditional
compilation, e.g. 

  -ifdef(POLITICALLY_CORRECT)
  pi() -> 3.0.
  -else.
  pi() -> 3.14159.
  -endif.

That can cause confusion along the lines of "am I debugging the code
I'm looking at", but how else do you solve that problem? 

The standard advice is to put the variant code in seperate
modules. Doing that has quite a disruptive effect on a program's
organisation---the classic example is that you have a working system
on hardware X and now you want to extend it to work on hardware
Y. Your choices are now

  a) Use conditional compilation and sprinkle changes throughout
     the code. Ugly because it uses the preprocessor and because
     code gets twice as long in many seperate places. Nice because
     it's fairly easy to convince yourself that you haven't broken
     the system for X.

  b) Re-structure the system so that there's a layer of redirection
     ("abstraction") which takes care of the differences between X and
     Y. Nice because it avoids the preprocessor. Ugly because it's
     harder to avoid creating double-maintenance problems and ugly
     because its more likely, in my experience, to introduce bugs
     to the otherwise 'stable' X target.

The implied question is: is there another way to achieve similar
effects to conditional compilation?

Matthias



More information about the erlang-questions mailing list