What’s an implied requirement?

I think we all know what an implied requirement is – it’s the unspoken expectation of the requirement we do specify.  As I was driving today, I was trying to find a simple example that would illustrate just how many decisions a software developer has to make when you leave requirements implied.  Not that you should necessarily expect that everything gets specified, just that you don’t always realize how much you are leaving to chance.

So, here’s my requirement: the user enters two numbers and the program adds them together and spits out the result.

That seems simple enough, and let’s say it’s a command line application, so no UI to deal with.  It should be all of about 4 lines of code, right?

Ok, but what if the user enters something that’s not a number?  Sure, simple right, we’ll just block non-numbers.  Well, except that there are some “non-numbers” which are numbers.  Pi (3.1415926…)?  e (2.71828)?  Should we allow those?  If this were a scientific app, we’d probably have to allow those.  And scientific notation perhaps as well (2.024 x 10^5)?

Ok, but what about irrational numbers (besides PI)?  Can the user specific 1/3 + 2/3 and get 1 or will your software return .999999999?  Some languages (like LISP) understand irrational numbers.  Others, like C, don’t natively.  I think most typical users would expect that fractions should be added properly, even if they’re irrational, but who’s to say for sure?

And what about i?  Imaginary numbers?  Do we support those?

How about the use of commas?  Is 1,234.56 considered valid?

What if the users enters something invalid?  Should we consider it a zero or return an error?  If we use C’s conversion functions, they’ll just convert invalid numbers into 0, which though an obvious implementation is probably not quite what you’d expect if you tried adding “2 + cat”, right?

Why bring this up?  Because the other day I saw code which checked a field for a valid number and it used a regular expression that looked like this: [09\.]*.  Unfortunately, that would allow “0.0.2” or “…” or “0…9” but not allow “1,234.56”.  Clearly, what appears simple is really not so simple.  A better regular expression (pardon that I didn’t test this out) would be: [09]*\.?[09]+. Which is to say, optional numbers followed by an optional “.” (but only one “.” if there is one at all) and then at least one mandatory digit.  That’s an improvement, but it doesn’t support commas, which are a bit more complicated yet.

People are good at understanding add two numbers and doing the right thing.  Computers are not.  And thus, the job of translating all those implied requirements falls to the developer, who may or may not do a good job at it.  It depends somewhat on what your developer thinks about and can be mitigated by utilizing some form of review process to ensure thoroughness.  But the point is simple, and at least as of this writing necessary to repeat.

When someone says “I want a programming language in which I need only say what I wish done,” give him a lollipop

Assume nothing, or at the very least you can assume that your developer will make the assumption for you and it may not be what you want.  It’s a trivial example, but you can quickly see how simple requests hide potentially significant issues.

Leave a Reply

Your email address will not be published. Required fields are marked *