[Haskell-cafe] The amount of CPP we have to use is getting out of hand

Johan Tibell johan.tibell at gmail.com
Fri Jan 9 13:55:06 UTC 2015


Hi,

(This was initially written as a Google+ post, but I'm reposting it here to
raise awareness of the issue.)

The amount of CPP we have to use in Haskell is getting a bit out of
hand. Here are the number of modules, per library, that use CPP for some of
the libraries I maintain:

containers 18/18
hashable 4/5
unordered-containers 6/9
network 3/7
cassava 4/16
cabal/cabal-install 13/75
cabal/Cabal 7/78
ekg 1/15

If this doesn't look like a lot to you (I hope it does!) consider than some
languages don't use CPP at all (e.g. Java).

CPP really sucks from a maintenance perspective:

 * It's not Haskell, but this bizarre string concatenation language.
 * The code is harder to read, bitrots more easily, and is harder to test.
 * The code can't be compiled without using Cabal (which generates some of
the CPP macros for us.) This hurts e.g. ad-hoc testing/benchmarking.

There are a couple of reasons we use CPP, but the main one is breaking
changes in GHC and libraries we depend on. We need to reduce these kind of
breakages in the future. Dealing with breakages and maintaining the
resulting CPP-ed code is costing us time we could spend on other things,
such as improving our libraries or writing new ones. I for one would like
to get on with writing applications instead of spending time on
run-of-the-mill libraries.

Often these breaking changes are done in the name of "making things
cleaner". Breaking changes, no matter how well-intended, doesn't make code
cleaner, it makes it less clean*. Users end up having to use *both* the old
"unclean" API *and* the new "clean" API.

The right way to move to evolve an new API is to add new functions and data
types, not modify old ones, whenever possible.

* It takes about 3 major GHC releases (~3 years) before you can remove the
CPP, but since new things keep breaking all the time you always have a
considerable amount of CPP.

-- Johan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20150109/7ff229a6/attachment.html>


More information about the Haskell-Cafe mailing list