NameSpace Pollution
⚠️ Why This Is Dangerous (Namespace Pollution)
Let’s say Math.sol contains:
library Math {
function add(uint a, uint b) public pure returns (uint) {
return a + b;
}
}
And later someone updates Math.sol and adds:
contract Helper {}
Now every file that has:
import "./Math.sol";
automatically gets access to:
- Math
- Helper
Even if you didn’t expect Helper to exist.
This is called:
🚨 Namespace Pollution
Risk of Name Conflicts
Imagine two different files both define:
contract Ownable {}
If you write:
import "./File1.sol";
import "./File2.sol";
Your code may suddenly stop compiling due to a naming conflict.
Explicit imports prevent this:
import{ Ownable as OwnableV1} from "./File1.sol";
import{ Ownable as OwnableV2} from "./File2.sol";
Now everything is clear and controlled.
Unexpected Breakage in the Future
Let's say today Utils.sol contains:
contract A {}
You import it using:
import "./Utils.sol";
Later, someone updates Utils.sol and adds:
contract Helper {}
Now Helper silently appears in your contract’s global scope. If you already have a Helper contract, your build may suddenly fail. You didn’t change your code but it broke.
That’s dangerous in large teams and production systems.
Reduced Readability
When auditors or teammates read your code:
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
They don’t immediately know what you're using.
But when you write:
import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
It’s obvious. Clear dependencies make:
- Audits easier
- Code reviews faster
- Security analysis cleaner Professional Solidity code should always make dependencies explicit.
Does It Affect Gas?
No.
Import style does not affect:
- Gas cost
- Runtime performance
- Deployment cost
- Bytecode size (unless you inherit or use additional code)
The compiler only includes what is actually used. Namespace pollution is a developer experience issue, not a blockchain performance issue.
Top comments (0)