473,396 Members | 1,871 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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

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 -

Jul 18 '06 #1
3 4039
ma*****@yahoo.com 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.
Jul 18 '06 #2
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...)

Jul 18 '06 #3
ma*****@yahoo.com 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.
Jul 18 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: pratchaya | last post by:
What the best language code to connect MySQL --> C , C++ , php,VB,Delphi ? about ---- Speed ---- Stable ---- Security Can anyone compare C , C++ , php4,php5 ,vb ,delphi to connect to...
17
by: | last post by:
I have an app that retrieves data from an Access database. At the moment I have the SQL string as a Const in my app. I understand this is not best practice. I don't want the user to have access to...
12
by: Perre Van Wilrijk | last post by:
Hi there, When I started using VB6, I used to write classes with properties and functions as following ... Private lngf1 As Long Private strf2 As String Public Property Get f1() As Long...
1
by: Rocael Hernandez | last post by:
Hello all, I was wondering what's best for PG, since we have to decide what will be the new server for our DB, that will serve one or more websites. Our actual configuration is a dual xeon...
1
by: Andrey Koptyaev | last post by:
I am owner of classicstars.com domain and now planning to build site. What the best CMS for this I can use ? Also I need info about rights for texts about stars and photos. Thank you!
1
by: TerryStone | last post by:
I am writing a Windows application, with an SQL Server (Express) database. The application is single user. The Windows application is the only application that accesses the database. I have...
2
by: kbutterly | last post by:
All, I have a menu which contains Category as the master and Product as the child. When I click on a Category in the menu, I want one formView control, fvpc, to show, and then when I click on...
8
by: pamela fluente | last post by:
I need an opinion. I have to add NEW pages to an existing site. The site has - also - some ASPX pages. These pages, I have seen, have the following doctype: <!DOCTYPE html PUBLIC "-//W3C//DTD...
7
by: Ashutosh Bhawasinka | last post by:
Hi, I have a C# .Net application which needs to use some feature which can be only developed in Visual C++ (its extended MAPI). The C# exe will be supplied to users without a setup. What kind...
8
by: SpecialKay | last post by:
Im just wondering what the term Handle count means?
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.