This Space for Rent

Code bloat

When I started writing Discount, I made all of the extensions selectable by #define. Well, this turned out to be a bad idea, so over the years I started tweaking the code so that I could turn features on and off at runtime. This project isn’t actually finished yet, but I’ve run into a teeny problem, in that I use a single 16 bit integer to hold flags, and I’ve now got 16 of them.

So what have I got?

flag what
0x0001 don’t do link processing, block <a> tags
0x0002 don’t do image processing, block <img>
0x0004 don’t run smartypants()
0x0008 don’t allow raw html through AT ALL
0x0020 process text inside an html tag; no <em>, no <bold>, no html or [] expansion
0x0040 don’t allow pseudo-protocols
0x0080 generate code for xml ![CDATA[...]]
0x0100 don’t process header blocks
0x0200 Expand tabs to 4 spaces, not the compiled-in default
0x0400 disallow tables
0x0800 forbid strikethrough
0x1000 do table-of-contents processing
0x2000 compatability with MarkdownTest_1.0
0x4000 make into a link even without <>s
0x8000 paranoid check for link protocol

(now, you might say that “oh, no, but integers are 32 bits” but I’m afraid that I’ve got a pdp-11 emulator here to tell you you’re wrong. And I’ve still got 6 or seven features that need to be turned on by default and then switchable by flag off. I could always just go for the trivial solution and have flag 0x0010 (MKD_STRICT) turn every extension off, but that doesn’t give me the sort of fine granularity I want to be able to have.)

So I’m going to have to break the interface after I release 1.6.8 and make all of the int flags arguments and fields into long flags. For 99% of the users out there, this probably won’t make any difference (does the iPod use 32 bit ints? I suspect so, but I can’t verify it because my (jailbroken) iPod touch doesn’t have a working set of C compiler libraries and thus I can’t get discount to compile on it) but the few, the proud, the retrogrouches who still use their pdp-11s to run their web servers would be very displeased to have discount silently break out from under them.

So (1.6.8++) is going to be 2, for some values of two. And maybe while I’m in the throes of breaking the interface I’ll strip out some of the meant-for-internal-use-only flags and force people to use the new(er) function calls that should be the only things that use those flags.