[Os-project-managers] ticket 14 - question about programming style
Horand Gassmann
Horand.Gassmann at Dal.Ca
Sat Nov 24 23:31:48 EST 2012
Hi guys,
quick progress report: I managed to write a new class OSOutput, which
contains the private Printf method that generates all of our output
along with an array of the output files and devices that are currently
defined.
So I have in the OSSolverServices main the following code:
OSOutput *osoutput = new OSOutput();
std::string versionInfo = OSgetVersionInfo();
osoutput->OSPrint(ENUM_OUTPUT_AREA_main,
ENUM_OUTPUT_LEVEL_always, versionInfo);
This puts the version info into stdout as well as any other files that
might have been defined bu the user.
However, I now have to make sure that the single instance osoutput is
visible in every method so I can process further output.
The way I see it there are three possibilities, each with its own drawbacks.
1. I can declare the instance as a global variable. I don`t like to do that.
2. I can set up a namespace, so that the variable is visible from
everywhere within the namespace. This is what Andreas does in Ipopt,
but I read that it is frowned upon, essentially for the same reason
that global variables are deprecated.
3. I can pass the instance as an extra argument to all methods that
use output (which is basically every routine we have ever written). As
far as I can see, this is clean, but it is cumbersome, and it blows
the API sky-high.
Any advice for me?
Cheers
gus
-------------------------------------------------------
Horand I. Gassmann, Professor
Kenneth C. Rowe School of Business, Dalhousie University
6100 University Avenue, PO Box 15000
Halifax, Nova Scotia, Canada, B3H 4R2
ph. (902) 494-1844
fax (902) 494-1107
http://myweb.dal.ca/gassmann/
More information about the Os-project-managers
mailing list