473,586 Members | 2,707 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

clean way to organize string constants (for user feedback)?

I've got some code that generates a report for the user. The report is
shown with explanatory verbage. The text is relatively long, and also
has some simple formatting (paragraphs, bulleted lists).

Right now the code is trivial, similar to the following:

if (5 == result) {
cout << "A value of five was returned because ...\n"
<< "\t- reason 1\n"
<< "\t- reason 2\n ...";
// etc
}
else {
cout << "The result was not five because ...";
<< "\t- reason 1\n"
<< "\t- reason 2\n ...";
// etc
}

Although simple, this makes for long, sloppy-looking functions.

Furthermore, the above example writes text to stdout, but I also have
code that generates an HTML version of the report. So, right now, I
effectively have the exact same code twice, once with text formatting
and again with HTML formatting. (And my long-term vision is to be able
to generate the report in *any* format, e.g. HTML, text, PDF, LaTeX,
etc.)

It seems like there should be a simpler, cleaner, more elegant means to
maintain this report verbage. The first thing that comes to mind is
creating a class of string constants. But, in order to use plain text
and HTML formatting, I'd basically have to devise some kind of grammar
or translation scheme. This seems like a lot of work for a fairly
trivial problem.

Another thought is to maintain the verbage in an XML file, create a
schema and use something like xerces-c to manipulate the XML. Again,
though, this seems like a complex solution for a simple problem.

I'm sure this is a fairly typical/common problem; anyone care to share
their favorite solution(s)?

Thanks!
Matt

--
Matt Garman
email at: http://raw-sewage.net/index.php?file=email
Jul 22 '05 #1
1 1869
I think the way is to write set of formaters (all with common abstract
parent). The formater will take the text (containing your own formating
marks) and answer text with formating marks for specific output.

The only thing the client is supposed to do is to construct new formater
(for wanted output) and let it format the text.

As the advantage new format can be add by creating new formater.

Milan Cermak

Matt Garman wrote:
I've got some code that generates a report for the user. The report is
shown with explanatory verbage. The text is relatively long, and also
has some simple formatting (paragraphs, bulleted lists).

Right now the code is trivial, similar to the following:

if (5 == result) {
cout << "A value of five was returned because ...\n"
<< "\t- reason 1\n"
<< "\t- reason 2\n ...";
// etc
}
else {
cout << "The result was not five because ...";
<< "\t- reason 1\n"
<< "\t- reason 2\n ...";
// etc
}

Although simple, this makes for long, sloppy-looking functions.

Furthermore, the above example writes text to stdout, but I also have
code that generates an HTML version of the report. So, right now, I
effectively have the exact same code twice, once with text formatting
and again with HTML formatting. (And my long-term vision is to be able
to generate the report in *any* format, e.g. HTML, text, PDF, LaTeX,
etc.)

It seems like there should be a simpler, cleaner, more elegant means to
maintain this report verbage. The first thing that comes to mind is
creating a class of string constants. But, in order to use plain text
and HTML formatting, I'd basically have to devise some kind of grammar
or translation scheme. This seems like a lot of work for a fairly
trivial problem.

Another thought is to maintain the verbage in an XML file, create a
schema and use something like xerces-c to manipulate the XML. Again,
though, this seems like a complex solution for a simple problem.

I'm sure this is a fairly typical/common problem; anyone care to share
their favorite solution(s)?

Thanks!
Matt


Jul 22 '05 #2

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

Similar topics

6
2008
by: kobu.selva | last post by:
I was recently part of a little debate on the issue of whether constants and string literals are considered "data objects" in C. I'm more confused now than before. I was always under the understanding that only "named" storage areas(from the standard) were data objects. Since constants and string literals don't have lvalues, they can't be...
8
4337
by: Duncan Winn | last post by:
I am new to VC++7. I am using a method GetPrivateProfileString that requires an LPTSTR. I have defined this as a: char * data_name; I am then trying to convert this to an LPOLESTR and I have done this as follows: LPOLESTR dunk_data = (LPOLESTR)T2CW(data_name);
7
7805
by: Sky | last post by:
I have been looking for a more powerful version of GetType(string) that will find the Type no matter what, and will work even if only supplied "{TypeName}", not the full "{TypeName},{AssemblyName}" As far as I know yet -- hence this question -- there is no 'one solution fits all', but instead there are several parts that have to be put...
1
5219
by: macupryk | last post by:
+ ex {"The name \"CHARACTER\" is not permitted in this context. Valid expressions are constants, constant expressions, and (in some contexts) variables. Column names are not permitted."} System.Exception {System.Data.SqlClient.SqlException} + dr {System.Data.DataRow} System.Data.DataRow dr "CHARACTER" object {string} dr "NAME" object...
232
13195
by: robert maas, see http://tinyurl.com/uh3t | last post by:
I'm working on examples of programming in several languages, all (except PHP) running under CGI so that I can show both the source files and the actually running of the examples online. The first set of examples, after decoding the HTML FORM contents, merely verifies the text within a field to make sure it is a valid representation of an...
1
2610
by: dellis | last post by:
Problem: My project was initially created without putting passwords in the connection string. When I added the password in the connection string, it disappears when performing a database fill. I have stepped through the code in debug and the connection string is correct up til the Fill command. Once the fill executes, the password disappears from...
18
1922
by: sinbad | last post by:
hi, why does the following program gives an runtime error ,instead of compilation error. anyone please shed some light. thanks sinbad ------------------------------ int main()
10
4565
by: Simon | last post by:
As title. How to clean out VSWebCache? Any good way to do that? Thanks.
54
3575
by: shuisheng | last post by:
Dear All, I am always confused in using constants in multiple files. For global constants, I got some clues from http://msdn.microsoft.com/en-us/library/0d45ty2d(VS.80).aspx So in header file writing: const double PI = 3.14; Every time using it, include the header file.
0
7912
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7839
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8202
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8338
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
6614
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5710
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5390
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
1
2345
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
1180
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.