For Programmers: Free Programming Magazines  


Home > Archive > Extreme Programming > July 2005 > Re: Untested == Undefined?









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Re: Untested == Undefined?
Laurent Bossavit

2005-07-24, 8:35 pm

Frosty,

> Or something similarly pointless. I wrote the test, I wrote the code. It now
> has the desired functionality. Or does it? What happens if I pass in a null
> string? What happens if I pass in a negative number?


This is the kind of situation where I'd typically add an assertion, to
explicitly state what cases I don't want to bother with:

public string TrimToLength( string stringToTrim, int lengthTrimmed )
{
assert( stringToTrim != null);
assert( stringToTrim.length() >= lengthTrimmed );
// implementation

Without the assertion, if the function is called with bad arguments it's
my problem - I haven't finished my job. With the assertion, if the
function is called with bad arguments it's the caller's problem.

Laurent

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com