Enrico Forestieri <[EMAIL PROTECTED]> writes: > > On Sun, Dec 09, 2007 at 06:59:36PM +0100, Uwe Stöhr wrote: > > > What's the problem? > > This code part is from Jürgen as proposal, because Angus and Abdel requested a solution without the > > declaration of the extern global variable as I did in the first version of the patch. > > When you have a cleaer solution, please post it. Better to learn now then to make the same mistake > > the next times. > > > > p.s. When you are a real C++ master, then please act like this! Look for example at > > http://www.mail-archive.com/lyx-devel-UqbJ+GOpo4+hPH1hqNUYSQ <at> public.gmane.org/msg133041.html > > to see how this is done gentlemen like. > > Uwe, the problem is that you happily bash others with harsh manners, > so you should not be surprised when you are paid with the same money. > Please, don't give me lessons about gentlemanliness when there are > posts in the archives demonstrating what a gentleman you are. > > That said, I am not a C++ master and don't feel to give lessons to > anyone. Anyway, the following code appears amusing even to me: > > +// the document's main language > +string document_language; > + > +string getDocumentLanguage() > +{ > + return document_language; > +} > + > + > +void setDocumentLanguage(string const & lang) > +{ > + document_language = lang; > +} > + > > See, you still have a global variable but nonetheless you introduce > two accessor functions to set and get its value, when it can still > be freely referenced from everywhere. > > So, please forgive me for having been in such a mood that didn't let me > refrain from returning some harshness.
The thing with politeness is, someone has to start. Uwe, your setter and getter *are* redundant as things stand, but I have a couple of other comments about them too: 1. They could both be called DocumentLanguage. No need to prepend with "set" and "get". 2. More importantly, getDocumentLanguage should return a "const &" to the variable. I agree with Abdel that this binary is very C-ish in structure. It would be a reasonable cleanup (IMO) to introduce a Tex2Lyx singleton class and access all global state through that. Something like: class Tex2Lyx { // Singleton pattern // Make the default ctor private. Will be invoked from the // singleton accessor. Tex2Lyx() {} // Make the copy ctor and assignment operator private. // Don't actually implement them. Tex2Lyx(Tex2Lyx const &); Tex2Lyx operator=(Tex2Lyx const &); static boost::scoped_ptr<Tex2Lyx> instance_; // Data members go here... string documentLanguage_; public: // I see that LyX.h defines "ref" and "cref" static functions // to return reference and const reference views on the global // instance_. It's probably best to do the same here... static Tex2Lyx & Instance() { if (Tex2Lyx::instance_.get() == 0) { instance_.reset(new Tex2Lyx()); } return *instance_; } string const & DocumentLanguage() { return documentLanguage_; } }; Your preamble.cpp code would then become: string const & documentLanguage = Tex2Lyx::Instance().DocumentLanguage(); Regards, Angus