* * * * * Tumbling through code, part II The oldest bit of code in mod_blog [1] deals with what I call “tumblers.” They're not true tumblers [2] as defined by Ted Nelson [3], but my implementation does allow a range to be specified. It's a date range rather than an arbitrary set of characters though. Obligatory Sidebar Links * Tumbling through Code [4] * Plan to throw one away. You will anyway … [5] * Collapsing tumblers [6] * Technical Details: Tumblers [7] And the reason the code hasn't changed in fifteen years is because it was hard to write the code [8], given the features I wanted to support at the time. Not only did I want the ability to specify a single entry, like 2015/07/18.2 [9], and a range of entries, like 2015/07/01-09 [10] but also have the ability to specify multiple, non-sequential entries, like 2000/08/11.1,2000/08/12.6,2000/08/13.4 while at the same time supporting the ability to specify ranges in reverse, like 2015/07/09-01 [11], all at the same time, like 2000/08/10.2-15.5,2015/07/09-01,2003/07/04.2. So while I got the code to support a forward range and a reversed range, in order to get the code out the door, I dropped the non-sequential selection of entries. The code just got too messy. But over the past fifteen years, a slew of issues popped up. First and foremost was the issue of redundant links: 2015/7/4.1 and 2015/07/04.1 both refer to the same page. This normally wouldn't be that big an issue except for Google [12], which eventually would penalize a website with duplicate content under different links (why do I even care about this? Do I really care about my Google page rank [13]? Enough to let it rule my code? Apparently I do. Sigh). Sure, I can tell that 2015/7/4.1 and 2015/07/04.1 are the same thing, and you can probably tell the same thing, but to a computer, it can't. Those are two distinct pages that just happen to have the same content. So I had to hack in code to generate redirects to address this issue. Now, 2015/7/4.1 would generate a redirect to the canonical version, 2015/07/04.1. But there were still some corner cases I didn't cover, such as 2015/07/04.01, which should redirect to 2015/07/04.1, or 2000/8/10.2-15.5 which should redirect to 2000/08/10.2-15.5. I finally had enough and decided over the weekend to fix the issue by rewriting the code. Yes, I know, you never rewrite code [14]! But in this case, it's not the entire program but a portion (granted, it's about the only portion that hasn't been rewritten) and it's not like the code is entirely bug free (it's not). It mostly works but the code as written was just too convoluted to salvage (in my opinion). Besides, I felt that a more straightforward, “parse it a piece at a time” approach over the “be clever and as geneneral as you can be” approach would be better. It was [15], although it took several further revisions to work out all the corner cases, such as the difference between 2015/04-2015/05 [16] and 2015/04/05-05/06 [17] (the first ending portion specifies a year and a month, whereas the second ending portion is a month and a day), checking the dates for validity [18], and fixing the ranges when reversed [19] (it wasn't as straightforward as I thought it would be—can you tell I haven't used this option all that much?). And not only did I manage to get 2000/8/10.2-15.5 [20] to redirect properly, but the reverse range 2000/8/15.5-10.2 [21] as well (check the links after clicking on them), all the while reminding myself “don't be afraid of special cases [22].” [1] https://boston.conman.org/about/ [2] https://en.wikipedia.org/wiki/Tumbler_(Project_Xanadu) [3] http://ted.hyperland.com/ [4] gopher://gopher.conman.org/0Phlog:2000/03/13.1 [5] gopher://gopher.conman.org/0Phlog:2000/04/28.1 [6] gopher://gopher.conman.org/0Phlog:2001/02/17.3 [7] https://boston.conman.org/about/technical.html [8] https://github.com/spc476/mod_blog/blob/cf476e063ffad19c818fc0b1168d13a874112b02/src/wbtum.c [9] gopher://gopher.conman.org/0Phlog:2015/07/18.2 [10] gopher://gopher.conman.org/0Phlog:2015/07/01-09 [11] gopher://gopher.conman.org/0Phlog:2015/07/09-01 [12] https://www.google.com/ [13] https://en.wikipedia.org/wiki/PageRank [14] http://www.joelonsoftware.com/articles/fog0000000069.html [15] https://github.com/spc476/mod_blog/blob/62ed40991f08e28e50d046d4510579bfb7bfa143/src/wbtum.c [16] gopher://gopher.conman.org/0Phlog:2015/04-2015/05 [17] gopher://gopher.conman.org/0Phlog:2015/04/05-05/06 [18] https://github.com/spc476/mod_blog/blob/62ed40991f08e28e50d046d4510579bfb7bfa143/src/wbtum.c#L85 [19] https://github.com/spc476/mod_blog/blob/62ed40991f08e28e50d046d4510579bfb7bfa143/src/backend.c#L190 [20] gopher://gopher.conman.org/0Phlog:2000/8/10.2-15.5 [21] gopher://gopher.conman.org/0Phlog:2000/8/15.5-10.2 [22] http://prog21.dadgum.com/27.html Email author at sean@conman.org