[Os-project-managers] ticket 14 - question about programming style

Kipp Martin kmartin at chicagobooth.edu
Mon Nov 26 02:12:01 EST 2012


Hi Gus:

I don't see a good solution right now.  I think the problem with 
solution 1 is that it makes the code no longer thread safe (I don't 
really understand thread safe, but I do know it important).  I don't 
much about the namespace idea. I did not know this was frowned on.

Cheers



>
> 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/
>
> _______________________________________________
> Os-project-managers mailing list
> Os-project-managers at list.coin-or.org
> http://list.coin-or.org/mailman/listinfo/os-project-managers


-- 
Kipp Martin
Professor of Operations Research
and Computing Technology
Booth School of Business
University of Chicago
5807 South Woodlawn Avenue
Chicago, IL 60637
773-702-7456
kmartin at chicagobooth.edu
http://www.chicagobooth.edu/faculty/bio.aspx?person_id=12825325568
http://projects.coin-or.org/OS

Sent without Blackberry, Droid, iPhone, or any other
wireless device.
-- 


More information about the Os-project-managers mailing list