{"action":"created","issue":{"url":"https://api.github.com/repos/sofa-framework/sofa/issues/39","repository_url":"https://api.github.com/repos/sofa-framework/sofa","labels_url":"https://api.github.com/repos/sofa-framework/sofa/issues/39/labels{/name}","comments_url":"https://api.github.com/repos/sofa-framework/sofa/issues/39/comments","events_url":"https://api.github.com/repos/sofa-framework/sofa/issues/39/events","html_url":"https://github.com/sofa-framework/sofa/issues/39","id":183886919,"number":39,"title":"Long nested namespace and source code readability & complexity","user":{"login":"damienmarchal","id":12644882,"avatar_url":"https://avatars2.githubusercontent.com/u/12644882?v=3","gravatar_id":"","url":"https://api.github.com/users/damienmarchal","html_url":"https://github.com/damienmarchal","followers_url":"https://api.github.com/users/damienmarchal/followers","following_url":"https://api.github.com/users/damienmarchal/following{/other_user}","gists_url":"https://api.github.com/users/damienmarchal/gists{/gist_id}","starred_url":"https://api.github.com/users/damienmarchal/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/damienmarchal/subscriptions","organizations_url":"https://api.github.com/users/damienmarchal/orgs","repos_url":"https://api.github.com/users/damienmarchal/repos","events_url":"https://api.github.com/users/damienmarchal/events{/privacy}","received_events_url":"https://api.github.com/users/damienmarchal/received_events","type":"User","site_admin":false},"labels":[{"id":452689164,"url":"https://api.github.com/repos/sofa-framework/sofa/labels/discussion","name":"discussion","color":"d4c5f9","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":7,"created_at":"2016-10-19T07:34:45Z","updated_at":"2017-03-24T11:20:14Z","closed_at":null,"body":"According to the Sofa guidelines: \nhttps://github.com/sofa-framework/sofa/blob/master/CONTRIBUTING.md\nwe have the following rule:\n\"You must avoid the using directive in header files (.h and .inl): using namespace foo.\" \nThe reason for this rule is that doing so generates namespace pollution which increase the risk of name collision. The drawback is that the long nested namespaces prefixes are repeated all around in the .h and .inl which impact readability.  \n\nWhat do you think of changing the rules and allowing to use \"using namespace\" and 'using' in the following context: \n\n``` cpp\nnamespace sofa\n{\n    namespace component\n    {\n         namespace engine\n         {\n                 namespace boxroi     // A per file namespace \n                 {\n                          using sofa::defaulttype::Vec3 ;\n                          using namespace sofa::whatever \n                          class BoxRoi \n                          {\n                                         // Here i can use Vec3 instead of sofa::defaultype::Vec3 or defaulttype::Vec3\n                          };\n                 }\n\n                using boxroi::BoxRoi ;         // declaring only the BoxRoi in the engine namespace to \n                                                           // the sofa current namespace structure.. \n         }\n    }\n}\n```\n\nWith such design the names imported in the boxroi namespace by 'using' and 'using namespace' are not leacking in the engine/component/sofa namespace. \n\nI see no side-effect of such design but maybe you do. \n\nDM. \n"},"comment":{"url":"https://api.github.com/repos/sofa-framework/sofa/issues/comments/288997070","html_url":"https://github.com/sofa-framework/sofa/issues/39#issuecomment-288997070","issue_url":"https://api.github.com/repos/sofa-framework/sofa/issues/39","id":288997070,"user":{"login":"damienmarchal","id":12644882,"avatar_url":"https://avatars2.githubusercontent.com/u/12644882?v=3","gravatar_id":"","url":"https://api.github.com/users/damienmarchal","html_url":"https://github.com/damienmarchal","followers_url":"https://api.github.com/users/damienmarchal/followers","following_url":"https://api.github.com/users/damienmarchal/following{/other_user}","gists_url":"https://api.github.com/users/damienmarchal/gists{/gist_id}","starred_url":"https://api.github.com/users/damienmarchal/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/damienmarchal/subscriptions","organizations_url":"https://api.github.com/users/damienmarchal/orgs","repos_url":"https://api.github.com/users/damienmarchal/repos","events_url":"https://api.github.com/users/damienmarchal/events{/privacy}","received_events_url":"https://api.github.com/users/damienmarchal/received_events","type":"User","site_admin":false},"created_at":"2017-03-24T11:20:14Z","updated_at":"2017-03-24T11:20:14Z","body":"Hi all\r\n\r\nI would be very happy if at the STC we re-warm the decision about having a clear naming scheme. \r\nSo if some of you are interested in this topic I suggest to book for one of our cofee break next week  :)\r\n\r\nMy current position on the issue is that:\r\n   - it become more and more messy as we have no 'applied' rule.\r\n\r\nTo me there is three interesting feature namespace should have each grounded by different needs:\r\n    - namespace that mimick path.\r\n    - namespace that group code logically. \r\n    - namespace that are short to write/read. \r\n\r\nSince c++11 it is very possible to have all that with a dual namespace scheme in which one  namespace match the files location. But as this namespace is in general long we have a second namespace organization that export the names in a more accessible namespace. \r\n \r\nEx (for a class in sofa/somehwere/again/MyClass.h): \r\n```cpp\r\n    /// namespace (hierarchical grouping)\r\n    namespace sofa {\r\n           namespace somewhere {\r\n                namespace again {\r\n                      namespace __myclass__ {\r\n                            /// This is a private namespace that I like a lot :) \r\n                            /// because we can import things we want with name leacking all around\r\n                            /// No more typedef when they are not needed :) \r\n                            /// The name here are available in __myclass__ (so normally only \r\n                            /// in the .cpp and .h and .inl) \r\n                            using std::vector; \r\n                            using sofa::defaultype::Vec;\r\n                            using sofa::suplercomplex::longns::OtherClass ; \r\n\r\n                            class MyClass : OtherClass\r\n                            {\r\n                                         MyCLass(Vec<3,float>&, ...) ; \r\n                            };\r\n}\r\n}\r\n}\r\n}\r\n````\r\n\r\nThen come the logical grouping in which the MyClass is exported into its logical group with 'using'\r\n```cpp\r\n    /// The second namespace schema (logical grouping)\r\n    namespace sofa {\r\n           namespace component {\r\n                  namespace collision {\r\n                          using sofa::somewhere::again::__myclass__::MyClass ;\r\n                  }\r\n           }\r\n    }\r\n```\r\n\r\nSo generally I such approach that this increase a lot the readability of the source code and conceptually this gives a taste of how python is handling import of modules and avoid nameclash. \r\n\r\n\r\n"}}
{"actor":{"display_login":"damienmarchal"}}