{"id":252,"date":"2009-07-15T14:12:15","date_gmt":"2009-07-15T19:12:15","guid":{"rendered":"http:\/\/www.padizio.com\/blog\/?p=252"},"modified":"2009-07-15T14:12:15","modified_gmt":"2009-07-15T19:12:15","slug":"rewriting-the-co-op","status":"publish","type":"post","link":"https:\/\/www.padizio.com\/blog\/2009\/rewriting-the-co-op\/","title":{"rendered":"Rewriting the Co-op"},"content":{"rendered":"<p><em>This is a second chapter in a series &#8211; the first chapter is <\/em>&#8220;<a title=\"Starting the Co-op\" href=\"http:\/\/www.padizio.com\/blog\/insights\/starting-the-co-op\/\">Starting the Co-op<\/a>.&#8221;<\/p>\n<p>Following that first successful cycle, we decided to wait through New Year&#8217;s, 2007 to open a new cycle.\u00a0 This gave me a nice, solid month to work away at the site, polishing away the last few bugs, and generally getting things locked down for production.<\/p>\n<p>I settled in, the second week in December of &#8217;06, to start patching up these past few bugs.\u00a0 What I quickly found, however, was that this software was nigh-unpatchable.\u00a0 Every time I&#8217;d try to add or remove a feature, everything would break.\u00a0 I don&#8217;t mean a couple error messages would show up &#8211; I mean the page would simply not appear.\u00a0 Locked up.\u00a0 No errors in the log.\u00a0 Dead.<\/p>\n<p>The Oklahoma software, you see, was built over several years, by people who were not professional programmers.\u00a0 They were students and foodies &#8211; and they did admirable work.\u00a0 Yet, there was not a consistent design standard or vision, and the result of that was a big ball of &#8220;spaghetti code&#8221; &#8211; code that&#8217;s great when the sauce is on it, but is awful if you need to change out specific noodles.\u00a0 (So that metaphor doesn&#8217;t work right.\u00a0 Oh well.)\u00a0 Plus, even they still considered the whole package &#8220;beta&#8221; &#8211; and not the &#8220;works really well Google-style&#8221; beta, either.<\/p>\n<p><!--more-->On top of that, the OK software had features we didn&#8217;t need to support.\u00a0 Their system is state-wide, and involves a whole transportation network.\u00a0 This means that farmers can drop off on one side of the state, volunteers then take apart the deliveries and load them onto trucks destined for other cities, and finally a day later everybody picks up their assembled orders from all over Oklahoma.\u00a0 Cool?\u00a0 Yes.\u00a0 But even then, we knew we weren&#8217;t going in that direction.\u00a0 We&#8217;re the West Michigan Co-op &#8211; not the Lower Peninsula Co-op.\u00a0 Not the All-of-Michigan Co-op.<\/p>\n<p>This turned out to be a huge part of their software &#8211; drop-off points, pick-up points, destination preferences, etc.\u00a0 And that code was intertwined in every single file of the site &#8211; again, spaghetti code.\u00a0 On top of that, some of the source files were nearly a thousand lines of code individually!\u00a0 Not maintainable, and thus not sustainable.<\/p>\n<p>It took me about a day of futile busywork on this jumble before I finally threw the code in the trash can.\u00a0 Bear in mind &#8211; we had already used this software.\u00a0 It kinda worked.\u00a0 And it was &#8220;finished.&#8221;\u00a0 Here I was, ready to start again, from scratch.\u00a0 What was I doing?<\/p>\n<p>At the time, I had recently stumbled upon a PHP framework called <a href=\"http:\/\/cakephp.org\">CakePHP<\/a>.\u00a0 If you&#8217;re a web programmer, you may have heard of it, or the framework it&#8217;s modeled after, <a href=\"http:\/\/rubyonrails.org\/\">Ruby on Rails<\/a>.\u00a0 If you&#8217;re not a programmer, I&#8217;ll just say this: CakePHP is essentially a library of code that you can build websites with.\u00a0 It&#8217;s designed to interact with databases similar to the one we had built with the Oklahoma software.\u00a0 It&#8217;s also designed for rapid development &#8211; meaning you can build an interactive site fast.<\/p>\n<p>I didn&#8217;t tell any of the other founders that I had done this &#8211; in fact, I left the old code up on the server just in case I couldn&#8217;t get it done.\u00a0 Farmers need the site to still be up anyway, just so they could update their product information.\u00a0 But at home, on my local server, I was crunching away, ten hours a day, rebuilding the Co-op software, piece by piece.\u00a0 I worked a solid three weeks on the new software.<\/p>\n<p>It was definitely a stressful time.\u00a0 But at the end of the three weeks, I had 95% of what the Co-op needed already implemented.\u00a0 So I took the plunge, and announced to Jerry, Gail, and Tom that I had killed the old code and started from scratch using this framework as a base.\u00a0 I published the site &#8211; which to the naked eye, looked exactly the same.\u00a0 Ordering wasn&#8217;t ready to go yet, but you could log in, farmers could maintain their product listings, and best of all, the back-end code was organized and solid.\u00a0 In fact, I even had RSS feeds of new products &#8211; something the old code wouldn&#8217;t have been able to do, probably ever, without writing a whole RSS library and SQL query from scratch.<\/p>\n<p>By the time we opened for ordering in January of &#8217;07, the last few features had been implemented.\u00a0 There were certainly a few bugs that first cycle with the new code, but over all, the ordering cycle went far smoother.\u00a0 Compared to the previous software, this was definitely less capable overall.\u00a0 Personally, this was a blessing, because it actually did what it was supposed to do &#8211; and nothing more.\u00a0 There weren&#8217;t any confusing options we weren&#8217;t using getting in the way.\u00a0 Best of all, of course, was that I had nice, stable, organized code to build on.<\/p>\n<p>I really don&#8217;t believe that I touched the code for the rest of January.\u00a0 It was exactly the same code in February &#8211; which was my test to make sure I hadn&#8217;t screwed up some strange time-related function.\u00a0 The January and February cycles went pretty well, considering the volume &#8211; which was rapidly increasing.\u00a0 I think we broke $1000 that February.<\/p>\n<p>Jerry designed some very nice looking PDF invoices, which we quickly adopted.\u00a0 I&#8217;ve found on numerous occasions that it&#8217;s practically impossible to get different browsers on different systems to print the same HTML page the same way.\u00a0 Why this is, I have no idea, but that&#8217;s how it is.\u00a0 (It can be done, but it takes an incredible about of debugging.\u00a0 Generating a PDF, on the other hand, is trivial by comparison.)<\/p>\n<p>Since then there have been lots and lots of features added to the software &#8211; product photos via Flickr, forums, a product search API, and lots of minor changes &#8211; but getting these new features has never caused a significant break in the software or restructuring.\u00a0 I&#8217;ve also <a href=\"http:\/\/code.google.com\/p\/online-co-op\/\">open-sourced the code<\/a>, to help others like the <a href=\"http:\/\/www.purpleporchcoop.com\/Order\/\">Purple Porch Co-op<\/a> in South Bend, Indiana get started.\u00a0 Like Oklahoma, I want to get others building their own local, online marketplaces.<\/p>\n<p><em>The story will continue in <\/em>&#8220;Structuring the Co-op.&#8221;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This is a second chapter in a series &#8211; the first chapter is &#8220;Starting the Co-op.&#8221; Following that first successful cycle, we decided to wait through New Year&#8217;s, 2007 to open a new cycle.\u00a0 This gave me a nice, solid &hellip; <a href=\"https:\/\/www.padizio.com\/blog\/2009\/rewriting-the-co-op\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[26],"tags":[],"class_list":["post-252","post","type-post","status-publish","format-standard","hentry","category-insights"],"_links":{"self":[{"href":"https:\/\/www.padizio.com\/blog\/wp-json\/wp\/v2\/posts\/252","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.padizio.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.padizio.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.padizio.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.padizio.com\/blog\/wp-json\/wp\/v2\/comments?post=252"}],"version-history":[{"count":5,"href":"https:\/\/www.padizio.com\/blog\/wp-json\/wp\/v2\/posts\/252\/revisions"}],"predecessor-version":[{"id":307,"href":"https:\/\/www.padizio.com\/blog\/wp-json\/wp\/v2\/posts\/252\/revisions\/307"}],"wp:attachment":[{"href":"https:\/\/www.padizio.com\/blog\/wp-json\/wp\/v2\/media?parent=252"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.padizio.com\/blog\/wp-json\/wp\/v2\/categories?post=252"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.padizio.com\/blog\/wp-json\/wp\/v2\/tags?post=252"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}