You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tuscany.apache.org by Jean-Sebastien Delfino <js...@apache.org> on 2006/12/21 00:58:30 UTC

[C++] Removing 'using' statements from includes

When refactoring the tuscany/sca/util classes, I noticed a number of 
'using namespace xyz' statements in some of our header files. I believe 
C++ practice is to avoid 'using' statements in a header file as they 
impact all cpp files that include the header and can cause name clashes. 
I think I contributed to adding some of these 'using' statements so I'm 
going to make some changes to our headers to help clean this :)

-- 
Jean-Sebastien


---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-dev-help@ws.apache.org


Re: [C++] Removing 'using' statements from includes

Posted by Jean-Sebastien Delfino <js...@apache.org>.
Pete Robbins wrote:
> On 21/12/06, Jean-Sebastien Delfino <js...@apache.org> wrote:
>>
>> Jean-Sebastien Delfino wrote:
>> > When refactoring the tuscany/sca/util classes, I noticed a number of
>> > 'using namespace xyz' statements in some of our header files. I
>> > believe C++ practice is to avoid 'using' statements in a header file
>> > as they impact all cpp files that include the header and can cause
>> > name clashes. I think I contributed to adding some of these 'using'
>> > statements so I'm going to make some changes to our headers to help
>> > clean this :)
>> >
>>
>> Done and committed under revision r489263.
>>
>> Both Linux and Windows build clean. I built all the extensions on Linux,
>> and all but the PHP extension on Windows, as it looks like it has not
>> been ported to VSExpress yet.
>>
>> As part of this code clean up I also organized the include statements in
>> the following order, to improve readability:
>> #include standard C++ headers
>> #include platform specific headers and runtime dependency headers
>> #include SDO headers
>> #include SCA headers
>>
>> The 'using namespace' statements are now only in .cpp files, and appear
>> after all the the #include statements.
>>
>> Finally, I adjusted the XSL stylesheets used to generate C++ proxies and
>> wrappers around C++ component implementations to use qualified names
>> instead of 'using namespace' statements. This will reduce the risk of
>> name collisions with user defined names in the generated code as well.
>>
>> -- 
>> Jean-Sebastien
>
>
> I think this is good practice. Did you do the SDO tree as well? I did go
> through and remove the "using namespace" statements many months ago 
> but left
> the individual statements like "using std::string". In the SDO tree there
> are some ordering requirements of includes, usually to stop confusing
> libxml.
>
> cheers,
>

Pete,

I had not done the SDO tree but since you asked I just did it now :) 
After removing the 'using' statements from the SDO headers (there were 
just 3 or 4, not many) I had to add 'using' statements to a few SCA .cpp 
source files to make them compile again, but the runtime source trees 
are all clean now. We still have a few 'using' in some SCA and SDO test 
cases but they are not harmful and we can leave them for now I think.

-- 
Jean-Sebastien


---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-dev-help@ws.apache.org


Re: [C++] Removing 'using' statements from includes

Posted by Pete Robbins <ro...@googlemail.com>.
On 21/12/06, Jean-Sebastien Delfino <js...@apache.org> wrote:
>
> Jean-Sebastien Delfino wrote:
> > When refactoring the tuscany/sca/util classes, I noticed a number of
> > 'using namespace xyz' statements in some of our header files. I
> > believe C++ practice is to avoid 'using' statements in a header file
> > as they impact all cpp files that include the header and can cause
> > name clashes. I think I contributed to adding some of these 'using'
> > statements so I'm going to make some changes to our headers to help
> > clean this :)
> >
>
> Done and committed under revision r489263.
>
> Both Linux and Windows build clean. I built all the extensions on Linux,
> and all but the PHP extension on Windows, as it looks like it has not
> been ported to VSExpress yet.
>
> As part of this code clean up I also organized the include statements in
> the following order, to improve readability:
> #include standard C++ headers
> #include platform specific headers and runtime dependency headers
> #include SDO headers
> #include SCA headers
>
> The 'using namespace' statements are now only in .cpp files, and appear
> after all the the #include statements.
>
> Finally, I adjusted the XSL stylesheets used to generate C++ proxies and
> wrappers around C++ component implementations to use qualified names
> instead of 'using namespace' statements. This will reduce the risk of
> name collisions with user defined names in the generated code as well.
>
> --
> Jean-Sebastien


I think this is good practice. Did you do the SDO tree as well? I did go
through and remove the "using namespace" statements many months ago but left
the individual statements like "using std::string". In the SDO tree there
are some ordering requirements of includes, usually to stop confusing
libxml.

cheers,

-- 
Pete

Re: [C++] Removing 'using' statements from includes

Posted by Jean-Sebastien Delfino <js...@apache.org>.
Jean-Sebastien Delfino wrote:
> When refactoring the tuscany/sca/util classes, I noticed a number of 
> 'using namespace xyz' statements in some of our header files. I 
> believe C++ practice is to avoid 'using' statements in a header file 
> as they impact all cpp files that include the header and can cause 
> name clashes. I think I contributed to adding some of these 'using' 
> statements so I'm going to make some changes to our headers to help 
> clean this :)
>

Done and committed under revision r489263.

Both Linux and Windows build clean. I built all the extensions on Linux, 
and all but the PHP extension on Windows, as it looks like it has not 
been ported to VSExpress yet.

As part of this code clean up I also organized the include statements in 
the following order, to improve readability:
#include standard C++ headers
#include platform specific headers and runtime dependency headers
#include SDO headers
#include SCA headers

The 'using namespace' statements are now only in .cpp files, and appear 
after all the the #include statements.

Finally, I adjusted the XSL stylesheets used to generate C++ proxies and 
wrappers around C++ component implementations to use qualified names 
instead of 'using namespace' statements. This will reduce the risk of 
name collisions with user defined names in the generated code as well.

-- 
Jean-Sebastien


---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-dev-help@ws.apache.org