Archive for February, 2010

Changing basic assumptions in apps

One of the hardest things for me as an app developer is changing basic assumptions in a safe, gradual way. Here’s an example.

Critter4Us is an app that reserves animals for demonstrations and student practice in a veterinary college. There are business rules like “an animal can be used to practice injections no more than twice a week”.

In its original form, Critter4Us only made reservations for one point in time (the morning, afternoon, or evening of a particular day). I’m now making it take reservations for “timeslices”, where a timeslice has a start date, an end date, and any subset of {morning, afternoon, evening}. Doesn’t seem like a huge change, but it turns out to be pretty fundamental:

  • A lot of questions vaguely like “is this point within this range?” are now “do these two ranges overlap?” There’s an existing Timeslice object (which, despite the name, was about points in time). It has some time-related behavior, but responsibility for some other behavior leaked out of it because the data was so simple.

  • Some of the database operations were annoyingly slow after being hard to get right, quite likely because my SQL-fu is weak. Since the questions are becoming more complex, I want to do less calculating when questions are asked and more stashing partial answers in the database. So adding this feature requires more database work than just a simple schema migration.

    (This feels like premature optimization of a feature I don’t know wouldn’t be fast enough, but my main motivation is that I’m more confident of getting the right answers if I stash partial answers. This is the most important business logic in the app.)

  • The UI needs to change. Should that be done by upgrading the existing reserve-a-point-in-time page (adding clutter for a case that’s used seldom) or adding a new page?

I want to make all these changes in such a way that (1) the tests are all passing most of the time and (2) the app is deployable most of the time. I devised the following strategy after writing a partial spike and throwing it away:

  1. DONE Change the current Cappuccino front end. It used to deliver

    ?date=2010-09-02&time=morning
    

    to the Sinatra backend. Now it delivers

    timeslice={'firstDate':'2010-09-02', 'lastDate':'2010-09-02', 'times':['morning']}
    

    This isn’t hard because the front end doesn’t do any calculations on the date.

  2. DONE Have the backend controller that receives the data quickly convert the new format into the old.

  3. DONE Move conversion of new-format-to-old into the Timeslice object. (Only two classes make Timeslice objects, so that’s easy.)

  4. DONE Change the Reservations table to add new columns. Change the Reservation object to allow it to be constructed using either the old or new format. Change all the non-test code to use the new constructor. (It’s convenient to keep the terser form around for the tests that use it.)

  5. IN PROGRESS
    Reservation and Timeslice aren’t completely dumb objects — they probably get told more than they get asked — but they do have accessors for date and time. Those accessors are still meaningful because (at this point) the first_date and last_date are always the same and the set of times can only ever contain one element.

    However, change their names to faked_date_TODO_replace_me and faked_time_TODO_replace_me. Run the tests. For each no-such-method failure,

    • If the purpose of the call can easily be expressed in terms of the new interface, rewrite the call to use it.

    • If not, use the convoluted, soon-to-be-replaced name.

  6. Replace the old code that answers the question “for which procedures may this animal be used at this moment?” with code that assumes cached partial answers. Mock out the cached partial answers and thereby design the partial answer table.

  7. Add the cached table to the database. Change the code that creates reservations to cache partial answers.

  8. Working from the controllers down, examine each method that uses faked_date_TODO_replace_me and faked_time_TODO_replace_me. What does the method do? What makes sense in a world where reservations and uses of animals are not for a single point in time? Where does the method really belong? Fix them.

  9. Now that all uses are fixed, delete the methods with silly names.

  10. Generalize the question-answering code to answer questions about timeslices more complicated than single points. Much careful testing here.

  11. Change the UI to collect more complicated timeslices.

It’ll be interesting to see what the final structure of the code looks like. A lot of this code was written early in the project, so I’m sure it’ll improve a lot.

If you want to see the code, it’s on GitHub.


  • Buy Cheapest inderal propranolol Online Free Viagra Pills! WorldWide Shipping.
  • Buy Cheapest levitra quit working Now Best Prices. Cheap Prescription Drugs.
  • Buy ultram drug test Online Without Prescription. Best Prices. Best Internet.
  • Buy Cheapest on rx legal diazepam Now Order Cheap Meds Without Rx. Best Prices.
  • Buy Cheapest vitamins store Online Discount Drugs At Best Online Drugstore.
  • Buy Cheapest levaquin 500mg Now WorldWide Shipping. Cheap Pharmacy Online.
  • Buy Cheap propecia canada Online Special Prices For propecia canada! Best Online.
  • Buy Cheap effects of lasix Now 24/Internet)(safe Pharmacy. Best Internet.
  • Buy Cheap over the counter muscle relaxants Now Cheap Online Pharmacy. Buy Medications Online.
  • Buy Cheap mexican ambien Online No Prescription Needed. Best Internet.
  • Buy Cheap ativan pills Now Cheap Online Pharmacy. 24/Online Pharmacy.
  • Buy Cheapest ambien coupon Online Free Viagra Pills! Guaranteed Shipping.
  • Buy Cheapest viagra price in brighton Online Best Drugstore. Guaranteed Shipping.
  • Buy Cheap us online pain medicine Online Best Prices. Discount Online Pharmacy.
  • Buy Cheapest generic ultram online Online Best Online. Discount Pharmacy Online.
  • Buy Cheapest cialis promotion Now Best Prices. The Largest Internet Pharmacy.
  • Buy Cheap levitra buy Now Guaranteed Shipping. Top Online Pharmacy.
  • Buy Cheapest clomid price Online Best Online. Cheap Prescription Drugs.
  • Buy Cheapest herbal impotence remedy Now Best Online. The Largest Internet Pharmacy.
  • Buying Cheap programs burning fat fast. Offshore Rx, Best Prices. Guaranteed Shipping.
  • Buy Cheapest muscle relaxer pain pill Online Online Medical Shop. Best Online.
  • drugs online no prescription Online Without Prescription Low Prices. Pharmacy Store.
  • Buy Cheapest order fucidin Online Low Prices. Cheap Online Pharmacy.
  • Buy Cheapest viagra online no rx Now Best Internet. Cheap Online Pharmacy.
  • Buy Cheapest curb appetite Now Cheap Online Pharmacy. WorldWide Shipping.
  • Buy Cheap canadian pharmacy internet Online Online Medical Shop. Cheap Online Pharmacy.
  • Buy Cheap buying medication from canada Now Guaranteed Shipping. Online Prices For buying medication from canada!
  • Buy Cheapest prescription medicine for back pain Now Cheap Online Pharmacy. Guaranteed Shipping.
  • Buy Cheap vitamin pill Now Drugs, Health And Beauty. Free Viagra Pills!
  • Buy Cheap levitra experiences Now Guaranteed Shipping. WorldWide Shipping.
  • Buy Cheapest buy xanax online no prescription Online Top Online Pharmacy. Best Online.
  • Buy Cheap clomid ovulation day Online Best Internet. Cheap Pharmacy Online.
  • Buy Cheapest cialis dysfunction erectile levitra Now Cheap Prescription Drugs. Best Internet.
  • Buy Cheapest buy pain killers Now 24/Online Pharmacy. Guaranteed Shipping.
  • Buy Cheap weight loss pill ratings Now Discount Online Pharmacy. Best Internet.
  • Buy Cheap discount vitamins online Now Best Internet. Special Prices For discount vitamins online!
  • Buy Cheap vpxl penis enhancement pills Now Guaranteed Shipping. Online Prices For vpxl penis enhancement pills!
  • Buy Cheap diazepam 10 mg usps online consultation Now Online Medical Shop. 24/Online Pharmacy.
  • Buy Cheap cost viagra cialis Online Online Medical Shop. Cheap Pharmacy Online.
  • Buy Cheap cialis overnight Online Free Viagra Pills! Online Medical Shop.
  • Buy Cheap addictive ultram Online Discount Pharmacy Online. Pharmacy Store.
  • Buy Cheap cheap pain pills Now The Largest Internet Pharmacy. Best Drugstore.
  • Buy Cheapest non narcotic pain reliever Online Best Drugstore. No Prescription Needed.
  • Buy Cheap medicine for stress Online WorldWide Shipping. Free Viagra Pills!
  • Buy Cheap online order viagra Now Pharmacy Store. No Prescription Needed.
  • Buy Cheap addiction to xanax Now Best Internet. Top Online Pharmacy Supplier.
  • Buy Cheap viagra and generic drug Now Free Viagra Pills! Cheap Prescription Drugs.
  • Buy Cheapest buying cialis online guide Now Best Prices. Internet Prices For buying cialis online guide!
  • Buy Cheap drugs levitra Online WorldWide Shipping. 24/Online Pharmacy.
  • Buying Cheap pain relief creams. Mexican Pharmacy, Good Prices. Pharmacy Store.
  • Buy tramadol cod delivery Online Without Prescription. Best Internet. Best Prices.
  • Buy Cheap discount drug Now Cheap Pharmacy Online. WorldWide Shipping.
  • Buy Cheap cialis offers Online Cheap Pharmacy Online. Best Internet.
  • Buy Cheap viagra without Now All Medications Are Certificated! Best Online.
  • Buy Cheapest clomid and fertility Now 100% Satisfaction Guaranteed. Low Prices.
  • Buy Cheap weight loss pills men Online 24/Online Pharmacy. Online Medical Shop.
  • levitra erectile dysfunction Online Without Prescription Best Internet. Best Prices.
  • Buy Cheapest cheap priced valium Now Drugs, Health And Beauty. Pharmacy Store.
  • discount online phentermine Online Without Prescription Best Internet. Best Prices.
  • Buy Cheap cheapest cialis index Now Top Online Pharmacy Supplier. Best Drugstore.
  • Buy Cheapest benefits of viagra Online Online Medical Shop. Best Online.
  • Buy Cheapest cialis testamonial Now Low Prices. Order Cheap Meds Without Rx.
  • Buy Cheap zoloft 50 mg Online Pharmacy Store. Cheap Online Pharmacy.
  • Buy Cheapest onset of action in valium Now Pharmacy Store. Buy Medications Online.
  • Buy Cheap alprazolam buy Online Discount Online Pharmacy. Best Drugstore.
  • Buy Cheap fat burner supplement Now Free Viagra Pills! Internet Prices For fat burner supplement!
  • Buy Cheap online shopping coupons for vitamin shoppe Online Best Internet. Discount Online Pharmacy.
  • Buy Cheapest cialis from canada Now Best Prices. Order Cheap Meds Without Rx.
  • Buy Cheap viagra online no prescription Now Online Medical Shop. Guaranteed Shipping.
  • Buy Cheap phentermine online no rx Now Free Viagra Pills! Cheap Online Pharmacy.
  • Buy Cheapest zoloft no prescription Now Cheap Prescription Drugs. Best Drugstore.
  • Buy Cheapest online order viagra Online Discount Pharmacy Online. Best Prices.
  • Buy Cheapest what is lorazepam used for Online Best Online. Special Prices For what is lorazepam used for!
  • Buy Cheap prescription drugs without rx Online Top Online Pharmacy. Free Viagra Pills!
  • Buy Cheapest online pharmacies no prescriptions Online Best Online. Top Online Pharmacy.
  • Buy Cheap ambien prescription Online Best Internet. Buy Medications Online.
  • Buy Cheap online propecia cheap Now Special Prices For online propecia cheap! WorldWide Shipping.
  • Buy Cheapest buy plavix on line Online Discount Pharmacy Online. Best Prices.
  • Buy Cheapest lorazepam prescription Now WorldWide Shipping. Cheap Online Pharmacy.
  • Buy Cheap prescriptions for back pain Online No Prescription Needed. Free Viagra Pills!
  • Buy Cheapest rdering prescription drugs without a prescription Online 24/Online Pharmacy. Free Viagra Pills!
  • Buy Cheapest zithromax chlamydia Now Special Prices For zithromax chlamydia! Pharmacy Store.
  • Buy Cheapest cialis dysfunction erectile levitra Online Best Prices. Guaranteed Shipping.
  • Buy Cheapest generic brands of viagra online Online Low Prices. Drugs, Health And Beauty.
  • Buy Cheapest prescription pills in mexico Now Guaranteed Shipping. Cheap Pharmacy Online.
  • Buy Cheapest doxycycline cheap Now Cheap Prescription Drugs. Best Internet.
  • Buy Cheap valium from pakistan Online 24/Online Pharmacy. Guaranteed Shipping.
  • Buy Cheapest cialis 50mg Now We Can Offer You Visit Our Online Pharmacy.
  • Buy Cheap online pharmacy spain Online Best Internet. Cheap Online Pharmacy.
  • Buy Cheap side effects of muscle relaxants Now Pharmacy At The Best Price! Pharmacy Store.
  • Buy Cheapest treating child obesity Now Cheap Online Pharmacy. Free Viagra Pills!
  • Buy Cheapest best buy viagra Now Pharmacy Store. Cheap Pharmacy Online.
  • Buy Cheapest online order ultram Online Best Online. Discount Online Pharmacy.
  • Buy Cheap viagra effect on women Now Cheap Meds Without Prescription. Best Online.
  • Buy Cheap generic viagra sales Now 100% Satisfaction Guaranteed. Best Drugstore.
  • Buy Cheapest discontinuing zoloft Now Online Prices For discontinuing zoloft! Best Prices.
  • Buy Cheapest how to buy erectile dysfunction medication Now Special Prices For how to buy erectile dysfunction medication! Low Prices.
  • Buy Cheapest finasteride 5 mg Online WorldWide Shipping. Guaranteed Shipping.
  • Buy Cheapest rapid weight loss Online Guaranteed Shipping. Pharmacy Store.
  • Buy Cheap order xanax online from mexico Online Discount Online Pharmacy. Pharmacy Store.