I Don't Like Imports
17 days ago
- #programming
- #imports
- #rust
- The author prefers not to import external symbols into the local scope to maintain code clarity and avoid ambiguity.
- Fully qualified names make it easier to copy and paste code between files without worrying about missing imports.
- Long names in libraries are often due to poor naming choices by library authors, not an inherent issue with fully qualified names.
- Avoiding imports helps prevent naming conflicts and ensures that the source of each symbol is clear.
- The author acknowledges that sometimes imports are necessary, especially for very long names, but prefers to keep their scope limited.
- In Rust, the author recommends providing a flat API and re-exporting symbols to avoid deep hierarchies.
- Traits in Rust can complicate the no-imports approach, but fully qualified method calls can sometimes be used instead.
- The author criticizes the deep hierarchy in Rust's standard library but accepts it as a reality to work around.