{"id":2897,"date":"2007-05-16T05:20:00","date_gmt":"2007-05-16T10:20:00","guid":{"rendered":""},"modified":"2020-03-27T21:30:20","modified_gmt":"2020-03-28T02:30:20","slug":"little-coding-exercise","status":"publish","type":"post","link":"https:\/\/henrymelton.net\/2\/2007\/05\/16\/little-coding-exercise\/","title":{"rendered":"A Little Coding Exercise"},"content":{"rendered":"<p>For many years, I spent all my workday at Motorola writing programs for internal use.  Before that, I even dabbled in commercial software.  But since then, the only coding I&#8217;ve done is a few tools for myself of my relatives.  Instead of designing software, I&#8217;ve been designing novels.<\/p>\n<p>But today I broke down and wrote a little addition to my website, a coupon manager.  The idea is that I can make a number of coupon codes that I can print on the back of my business cards, or hand out at conventions.  A person would then go to the Coupon page on my website and enter the magic code.  Then, they would receive a download or special offer or something (I haven&#8217;t worked all that out yet.)<\/p>\n<p>The core of the software was a little XML database containing coupon codes, what was to be offered, and how many times the same code could be used before it expired.  Seeing that I&#8217;d written other software using dumbed-down XML databases, I copied over the bulk of the code from the software that I&#8217;d written for my wife <a href=\"http:\/\/MaryAnnMelton.com\">Mary Ann Melton&#8217;s website<\/a> and my sister <a href=\"http:\/\/MarySolomon.com\">Mary Solomon&#8217;s site<\/a>.  These are all dynamic sites that generate the pages on the fly from an XML database.<\/p>\n<p>All went well and the program came together fairly quickly.  Then, as is often the case, a puzzling bug appeared.<\/p>\n<p>I had populated the database with three items, each with their own counters.  I was happily entering coupon codes and downloading test files, when all of a sudden, everything stopped working.  Once the first test file reached the end of its counter limit, none of the codes could be recognized anymore.<\/p>\n<p>I puzzled over it.  I wrote debugging code.  I reset the counters.  It repeated.  Once ANY ONE of the coupons reached its expiration limit, ALL of the codes became invalid.<\/p>\n<p>Finally I gave up trying to debug the new subroutines I had created and started following the logic even into the old code that had happily been producing web pages for years.  And there it was.  Off in a subroutine that parsed the XML database into variables, was a rare bug that caused the parser to fail once it saw &#8216;0&#8217; as a value.  In all the time that it had been working to create web pages, there had never been an element that contained nothing but a single zero, so it had never failed.<\/p>\n<p>Now, mystery solved.  I just have to decide whether to recode the parser ( an opaque one-liner regular expression), or just to write the code to never reach zero.<\/p>\n<p>You know, coding is much more fun than SudoKu.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>For many years, I spent all my workday at Motorola writing programs for internal use. Before that, I even dabbled in commercial software. But since then, the only coding I&#8217;ve done is a few tools for myself of my relatives. Instead of designing software, I&#8217;ve been designing novels. But today I broke down and wrote&hellip; <a class=\"more-link\" href=\"https:\/\/henrymelton.net\/2\/2007\/05\/16\/little-coding-exercise\/\">Continue reading <span class=\"screen-reader-text\">A Little Coding Exercise<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_newsletter_tier_id":0,"jetpack_publicize_message":"","jetpack_is_tweetstorm":false,"jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false}}},"categories":[1],"tags":[222,380],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p4t90x-KJ","_links":{"self":[{"href":"https:\/\/henrymelton.net\/2\/wp-json\/wp\/v2\/posts\/2897"}],"collection":[{"href":"https:\/\/henrymelton.net\/2\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/henrymelton.net\/2\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/henrymelton.net\/2\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/henrymelton.net\/2\/wp-json\/wp\/v2\/comments?post=2897"}],"version-history":[{"count":1,"href":"https:\/\/henrymelton.net\/2\/wp-json\/wp\/v2\/posts\/2897\/revisions"}],"predecessor-version":[{"id":2898,"href":"https:\/\/henrymelton.net\/2\/wp-json\/wp\/v2\/posts\/2897\/revisions\/2898"}],"wp:attachment":[{"href":"https:\/\/henrymelton.net\/2\/wp-json\/wp\/v2\/media?parent=2897"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/henrymelton.net\/2\/wp-json\/wp\/v2\/categories?post=2897"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/henrymelton.net\/2\/wp-json\/wp\/v2\/tags?post=2897"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}