This post is for all of my non-programmer readers who have to deal with programmers on a day to day basis. It’s a description of how things that may seem simple really aren’t. Maybe I’ll write another post later about how things that seem complicated can be very simple to fix.
I’m working on a Web page that is supposed to display some events from a Google calendar. When I started, it grabbed the JSON feed from the calendar and displayed the first two events in it. Generally speaking, these are the next two upcoming events on the calendar. The feed contains a lot more events, though — some from the past and a lot from the future.
Unfortunately displaying the first two events in the feed did not meet the exact requirement, which turned out to be: display the events from the first two upcoming dates on the calendar. If there are multiple events on one of those dates, show them all. If there are not two upcoming dates, show one or two dates from the most recent past (so that two dates are always displayed).
Outwardly, this seems simple. Reorder the calendar in ascending order and pick the right slice of events to show.
The old code just grabbed the first two events in the list and printed them. The new code had to do the following:
- Extract the dates from the feed and convert them into JavaScript Date objects.
- Sort the events from oldest to most recent.
- Split the events into two lists — events in the future and events in the past.
- Iterate over the future events, picking out the events from the next two dates, and adding them to a third “events to display” list.
- If there are not two dates with events in the future, sort the events from the past in the future in descending order then pick out enough dates to fill out the “events to display” list.
- Sort the “events to display list” in ascending order.
- Display the final list of events.
Making that list was easy, but figuring out all of the requirements and then coming up with the best way to implement the solution took plenty of time from the point when the designer said “sort the events in ascending rather than descending order” to the time it was deployed. And all this for one little module on a page that contains lots of other information.
This is why I generally forbid the use of the word “just” when people are making feature requests. When it comes to developers, the word I forbid is “should,” but that’s another story.
April 6, 2009 at 3:27 pm
Great post! Calendars and Date formats in general are always a thorn in one’s side, but I think you briefly explained to none-developers how something seemly so simple (and for only one part of the page) can require so much planning and work.
I’m looking forward to reading… “Should: The forbidden word”
Cheers!
April 6, 2009 at 3:28 pm
Doh! That should be “Non” not “None”.