-
Notifications
You must be signed in to change notification settings - Fork 363
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Move using-declarations into class body to avoid polluting the global namespace #1186
Conversation
Should we instead remove the |
Sure, looks like geos prefer explicit namespace in header file but |
Hi , I thkink I known what you mean, and I notice that a lot of code using such Since c++ api is one way of using geos, such effort to avoid multiple declaration is necessary and meaningful. The key is using which code style to sove this, remove |
The practice in the code base is a mishmash, I can see trying to move to fewer uses of |
Won't that mean a lot more scoping of names used in multiple places in the file? Isn't |
@@ -93,27 +86,27 @@ class GEOS_DLL OffsetCurve { | |||
private: | |||
|
|||
// Members | |||
const Geometry& inputGeom; | |||
const geom::Geometry& inputGeom; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what about doing the following (generalized to similar cases), to both reduce verbosity and amount of lines changed ?
const geom::Geometry& inputGeom; | |
using Geometry = geom::Geometry; | |
const Geometry& inputGeom; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So use using
as a type alias instead of a using declaration? Is this safer in some way?
What is the scope of the alias? Is it just the namespace within the cpp
file including the header? Or is it the entire namespace (seems unlikely, since how would other compilation units see it?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the scope of the alias?
the class in which you put it
Not saying this is a good idea. Mostly for brainstorming
Why not just moving the |
If you check
I think it's a good practice inside implementation files, where you're not exporting the shorthand to anyone including the header.
Because then we've polluted the If you instead put the |
Do you mean "put the If so, does the following capture the recommended practice?:
|
Yes
I don't know if I'd call it a recommend practice, just trying to clarify the difference between putting it inside and outside the class definition. If you look at a header like
Yes |
I'am back, I've learned a lot from your conversations. It looks like "put the using type alias inside the class" is an acceptable solution, I am trying to fix all the header files in this way: type alias always on the top of the class. So alias is private to the class without leaking. But according to my statistics, there are at least 59 header files need to fix, it may take several days to finish. class GEOS_DLL OffsetCurve {
using Coordinate = geos::geom::Coordinate;
using CoordinateSequence = geos::geom::CoordinateSequence;
using Geometry = geos::geom::Geometry;
using GeometryFactory = geos::geom::GeometryFactory;
using LineString = geos::geom::LineString;
using Polygon =geos::geom::Polygon;
private:
// Members
const Geometry& inputGeom;
double distance;
bool isJoined = false; |
Are the forward declarations still needed? Would be nice if that cruft could be eliminated. I guess they need to be replaced by
|
I think there's a compile time penalty to including everything. |
Forward declarations break the dependency chain, so a change in |
Yeesh, how fiddly. But this usage should be encouraged, sounds like. |
0a6fec7
to
6bfb777
Compare
Ready for review. Note that sometimes I prefer |
Polygon, LineString, etc., are declared in the global namespace with the using-declaration keyword, which is very likely to confilict with other types of the same name.
Move them to geos::operation::buffer fixes this.
geos/include/geos/operation/buffer/OffsetCurve.h
Lines 39 to 50 in 46972ad