Re: unit testing C++ code from perl
- From: Phlip <phlip2005@xxxxxxxxxxxx>
- Date: Thu, 06 Jul 2006 23:03:04 GMT
Nick Keighley wrote:
what! Its *good* to have no comments?! Not even a one liner saying what
it's
*for*?
Ahem.
void ReportAssert(char const* description, char const* filename, int const
lineNumber)
Oookay. We have a function called ReportAssert, and it takes a
description. That's probably the complaint string for an error. "The
frob doesn't fit its Wibble socket", or whatever.
Then we have a filename and lineNumber. They are probably just the same as
the filenames and lineNumbers we have seen ever since we were little
kiddie-programmers.
Oh, and we didn't get creative with the names, like fileN or lNumber.
Those would have required comments. Like fileN // this is the filename,
and lNumber // this is the line number.
Let's try another one.
template<typename ValueType>
void FormatToStream(MemoryOutStream& stream, char const* format, ValueType const& value)
{
char txt[32];
std::sprintf(txt, format, value);
stream << txt;
}
Hmm. That seems to format any primitive value as a string, then insert
it into a string. It probably wraps the "%2.0i" format flags that sprintf()
is famous for. And we are not production code, so we don't need
snprintf() or something more over-flow safe. But any comment I wrote
describing everything going on would be bigger than the function!
If you ask "what about the hard, complex methods?" that's the point -
there are none. All the functions are short, cheap, narrow, and obvious
like these. (There are those who claim unit testing helps generate such
code!)
Treat all comments as a failed opportunity to improve the code's clarity.
BTW I wrote a tutorial for UnitTest++, here:
http://wiki.orbzone.org/TestFirstCiao
Disregard the CIAO stuff. It would need ... lots of comments!
--
Phlip
.
- Follow-Ups:
- Re: unit testing C++ code from perl
- From: Nick Keighley
- Re: unit testing C++ code from perl
- References:
- Re: unit testing C++ code from perl
- From: Tom Plunket
- Re: unit testing C++ code from perl
- From: Nick Keighley
- Re: unit testing C++ code from perl
- From: Phlip
- Re: unit testing C++ code from perl
- From: Phlip
- Re: unit testing C++ code from perl
- From: Nick Keighley
- Re: unit testing C++ code from perl
- Prev by Date: Cool Ebooks Site
- Next by Date: Re: Cool Ebooks Site
- Previous by thread: Re: unit testing C++ code from perl
- Next by thread: Re: unit testing C++ code from perl
- Index(es):
Relevant Pages
|