Hacker News new | ask | show | jobs
by gadrfgaesgysd 3939 days ago
What a macro fest: https://github.com/concurrencykit/ck/blob/master/include/gcc... https://github.com/concurrencykit/ck/tree/master/include/gcc

This might not be the intention of the author, but if you want someone to use/hack with your library, please make it human-readable. Those macros reduce the amount of duplication, at the cost of legibility. At least include useful comments... /rant off

4 comments

To each his own. As far as macro fests go, that file looks very reasonable and legible to me. It's a single pattern repeated consistently for each function family. Writing out a dozen variants of each function explicitly would not only be much more error-prone, but would also be much harder to read and understand as a whole IMHO.
These are clean macros. Macros do have their place and not every time you see a macro your macro red flag should go off.

It took me less than a minute scrolling through the file to figure out what's going on.

It's actually used as a way to avoid casting into and out of void* on every line. Think C++ templates. The documentation is somewhat lacking, but it's not too hard to figure out the APIs, and once you do, actually using the library is a pleasure.
Code duplication can also mean more errors and a lot more work for porters. You'll also see plenty of other examples in popular open-source projects such as the Linux and FreeBSD kernel. The reduction in amount of duplication is significant.

For example: For SPARCv9 for example, the macro system generates 138 functions from only the 25 or so the developer provides. To top it off, this would work across memory models as well.