On 22-1-2014 21:25, mathog wrote:
Sometimes it is hard to shake off decades of C programming, so please bear with.
In src/display/drawing-context.h near the top one finds:
class DrawingContext : boost::noncopyable { public: class Save { public: Save(); Save(DrawingContext &ct); ~Save(); void save(DrawingContext &ct); private: DrawingContext *_ct; };
and in drawing-context.cpp those methods all use ct and _ct for the variable names. Which is all fine and would be no issue at all, except that below the lines just cited in drawing-context.h every place one finds a reference to ct or _ct it is a cairo_t or a cairo_t*, not a DrawingContext.
Can somebody please explain why it is considered helpful in C++ to use "ct" to mean two different things like this in the one header file?
The disadvantage of doing it the way it is now is that when somebody like me encounters _ct elsewhere in src/display, and looks for it like this:
grep '[\* ]_ct[; {]' src/display/*.h
it finds two definitions:
DrawingContext *_ct;
and
cairo_t *_ct;
with the end result that one must read the file to figure out what is actually going on. Had the first set used "DC"/"_DC", for instance, there would have been no confusion, and the second step would have been eliminated.
I don't think this has anything to do with C/C++.
There is no name clash (the one is "DrawingContext::Save::_ct", the other "DrawingContext::_ct"), but it is confusing and I agree the former should be changed.
- Johan