Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > what's the best way to handle the verbose mode of an application ?

Reply
Thread Tools

what's the best way to handle the verbose mode of an application ?

 
 
mast2as@yahoo.com
Guest
Posts: n/a
 
      07-18-2006
In the same vein as the topic that I started on exception handling
.... If I have read (not all of them though) the documents that you
guys pointed me to, the try/throw/catch mechanism should really be kept
for exception handling (basically errors whevere they are critical or
not). Now, while I am developing this application, so far I used
std::cout quite a lot to check that the code was doing the right thing
(writing out to the console the content of some variables, etc). Now
that the program becomes more complex and that I need to develop some
over parts of the application, I would like to start removing those
lines. Of course at the same time i am thinking that I may need them
back again one day so commenting them out or deleting them doesn't seem
to be the best option, ... so my question is... What would the best way
to implement some sort of verbose system in a program where for example
the user can specify how 'chatty' he/she wants the output to be (myapp
-verbose 1).
So far what I have been using is the very basic thing like

#define VERBOSE 1

#ifdef VERBOSE
std::cout << "write something out to the console" << std::endl;
#endif

but i know from you guys know that macro are evil , plus this
mechanism doesn't handle the level of verbosity that a user might want
to set (0 silent, 1 basic info, 2 every possible message).

Should I just write a simple inline function like printOutInfo and use
it whenever I have something to print out to the console, something
like... (code not tested)

enum VerboseLevel
{
kSilent = 0,
kPrintImportantStuff,
kPrintEverything
};

void printOutInfo( const char* msg, VerboseLevel msgVerboseLevel,
VerboseLevel userVerboseLevel
{
if ( userVerboseLevel != kSilent && userVerboseLevel >=
msgVerboseLevel )
{
std::cout << msg << std::endl;
}
}

int main( int argc, char *argv[] )
{
VerboseLevel userVerboseLevel = (VerboseLevel) atoi( argv[ 1 ] );
printOutInfo( "some very important message", kPrintImportantStuff,
userVerboseLevel );
return 0;
}

Or is there a good way to do that, that someone described already
somewhere

Many thanks, Mark -

 
Reply With Quote
 
 
 
 
Ian Collins
Guest
Posts: n/a
 
      07-18-2006
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> In the same vein as the topic that I started on exception handling
> ... If I have read (not all of them though) the documents that you
> guys pointed me to, the try/throw/catch mechanism should really be kept
> for exception handling (basically errors whevere they are critical or
> not). Now, while I am developing this application, so far I used
> std::cout quite a lot to check that the code was doing the right thing
> (writing out to the console the content of some variables, etc). Now
> that the program becomes more complex and that I need to develop some
> over parts of the application, I would like to start removing those
> lines. Of course at the same time i am thinking that I may need them
> back again one day so commenting them out or deleting them doesn't seem
> to be the best option, ... so my question is... What would the best way
> to implement some sort of verbose system in a program where for example
> the user can specify how 'chatty' he/she wants the output to be (myapp
> -verbose 1).


Save your self a lot of unnecessary grief and learn Test Driven
Development. With proper robust unit tests, incremental development
makes this stuff redundant.

--
Ian Collins.
 
Reply With Quote
 
 
 
 
mast2as@yahoo.com
Guest
Posts: n/a
 
      07-18-2006

> Save your self a lot of unnecessary grief and learn Test Driven
> Development. With proper robust unit tests, incremental development
> makes this stuff redundant.


Hum sounds like another thing I need to learn

That's fine for debugging my application I guess (so I am going to read
about Test Driven Development) but let's say i also need to output some
data for the user if he/she wants it (progress report, some average
value about processing times, created files, etc...)

 
Reply With Quote
 
Ian Collins
Guest
Posts: n/a
 
      07-18-2006
(E-Mail Removed) wrote:
>>Save your self a lot of unnecessary grief and learn Test Driven
>>Development. With proper robust unit tests, incremental development
>>makes this stuff redundant.

>
>
> Hum sounds like another thing I need to learn
>
> That's fine for debugging my application I guess (so I am going to read
> about Test Driven Development) but let's say i also need to output some
> data for the user if he/she wants it (progress report, some average
> value about processing times, created files, etc...)
>

Than that becomes a user story and you do it in the normal way. What the
user wants should not be confused with what the developer wants.

--
Ian Collins.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Non-verbose, simple way of getting pixels of an image? maestro Java 13 07-17-2008 01:31 AM
Verbose mode for Firefox & SeaMonkey ? Stegozor Firefox 0 06-14-2006 02:46 PM
Test::Unit verbose mode Phlip Ruby 1 10-24-2004 08:18 AM
Test::Unit verbose mode Phlip Ruby 0 10-23-2004 07:04 PM
verbose mode Jooooooeeeeeeeeeeeeeeee MCSA 1 12-08-2003 06:13 PM



Advertisments