There’s a very clever piece of design advice that I was taught at university that seems to be less well known than I expected.

A computer science lecturer of mine once said:

There are ony three possible numbers in computer science. Zero, One, and Infinity.

Unfortunately, I can’t remember which of my lecturers it was. If you were in any of my classes - and you recognize the quote, please let me know!

At first glance this advice seems a bit odd. Surely there are cases where other numbers are useful.

Over the course of my career, I’ve run into significant difficulties every time I’ve thought a different number was appropriate.

Here’s an example.

How do you capture the opening hours of a business for each day?

Imagine you are building an application for a small takeway burger bar called The Burger Box. Betty, the owner, tells you that she is open seven days a week, opening at 11am each day for the lunch crowd. Closing time varies each day, with Friday and Sunday extending into the wee small hours of the following morning.

One, very straightforward, approach is to capture the opening & closing hours for each day of the week. Exactly seven pairs, seeming to capture the requirements well - and the number of days in the week isn’t going to change any time soon.

But problems soon emerge.

How do you capture days where the business is required to close for the day?

In New Zealand, most businesses are required to be closed on certain official holidays such as Christmas Day, Good Friday, and Easter Sunday.

Or what do you do when the hours of opening are different - as they are on Anzac Day, where businesses have to be close for the morning but are permitted to reopen at 1pm.

Both of these require support for defining opening hours that aren’t based on the day of the week.

Or, what do you do when you want to change the hours of opening - say if Betty decides to open at 4pm on Monday through Thursday because the lunchtime business has declined.

This requires support for changing the hours of opening for a specific day of the week, effective from a particular date.

It’s clear that seven is an impossible number here. Hard coding support for seven different opening hours just doesn’t work: it fails as soon as it encounters the real world.

For this situation, the only real number has to be infinity. You need to support an open ended list of opening hour rules.

Comments

blog comments powered by Disqus
Next Post
Logging Implementation  25 Jan 2020
Prior Post
Logging Demonstrated  11 Jan 2020
Related Posts
Using Constructors  27 Feb 2023
An Inconvenient API  18 Feb 2023
Method Archetypes  11 Sep 2022
A bash puzzle, solved  02 Jul 2022
A bash puzzle  25 Jun 2022
Improve your troubleshooting by aggregating errors  11 Jun 2022
Improve your troubleshooting by wrapping errors  28 May 2022
Keep your promises  14 May 2022
When are you done?  18 Apr 2022
Fixing GitHub Authentication  28 Nov 2021
Archives
January 2020
2020