Skip to content
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

Stop using using namespace in header files #20

Open
fvranicTT opened this issue Feb 24, 2025 · 2 comments
Open

Stop using using namespace in header files #20

fvranicTT opened this issue Feb 24, 2025 · 2 comments
Labels
good first issue Good for newcomers

Comments

@fvranicTT
Copy link
Contributor

Description

Using using namespace in header files is generally considered bad practice because it can lead to namespace pollution and unexpected name conflicts. When you include a header file that uses using namespace, it brings all the names from the specified namespace into the global namespace of any file that includes it. This can cause name collisions and make the code harder to understand and maintain. At the moment of writing this issue, we have 183 using directives in 149 files. Since this is a header-only project, I'd say we have this issue in almost 60% of files.

Why This Is a Problem

Namespace Pollution: All names from the "used" namespaces are brought into the global namespace, which can lead to unintended name clashes.
Code Maintainability: It becomes difficult to track where certain names are coming from, making the code harder to read and maintain.
Potential Conflicts: If another header file or source file includes the same header and defines names that conflict with those in the namespace that was included using using namespace directive, it can lead to compilation errors or unexpected behavior.

Solution

Remove using namespace directives: Remove the using namespace directives from all of the header files and fully qualify the names from namespaces where they are used.

@fvranicTT fvranicTT added the good first issue Good for newcomers label Feb 24, 2025
@JushBJJ
Copy link

JushBJJ commented Feb 27, 2025

I'm doing tenstorrent/tt-metal#7736, would you like it if I voluntarily remove using namespace sfpi as well on the ckernel_sfpu_*.h files? The OPs work without it

@fvranicTT
Copy link
Contributor Author

Sounds awesome! Thanks for cleaning up our yard! 👏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants