Applying "Programming Without Pointers" to an mbox indexer using Zig

24 points by deevus


epilys

A note to all people writing their own mbox code: the format is not that simple. You have to know in advance what kind of mbox subformat you are dealing with (mboxo, mboxrd, mboxcl, mboxcl2). Otherwise you have to use heuristics on a best effort basis.

All formats except for mboxcl2 escape lines in the message body starting with "From " as ">From ". Some of the formats rely on scanning for the next "From " line to find the next message, some don't (they use a Content-Length header). Some times the mbox file is a mix of those conventions. Fun!

A good primer is here: https://www.loc.gov/preservation/digital/formats/fdd/fdd000383.shtml

weberc2

The article opens by claiming PWP (programming without pointers) is about avoiding allocations, but you can use pointers without heap allocating memory. You can use pointers into stack allocations or you can preallocate an array once and use pointers into the array.

Also, heap allocations aren’t terrible in all GC languages. Many Java GCs make allocations very cheap—almost the same cost as a stack allocation. Or at least that’s my understanding anyway!

Not trying to nerd snipe here—I think this stuff is interesting, and I agree with the author’s enthusiasm about avoiding unnecessary allocations.