How do developers store code for the compiler, and access it for reuse?
Adopt an approach with tiered files, libraries, packages and namespaces in the design.
Related issues that are out-of-scope for this proposal are:
Access control: while there is some implicit access control from interface vs implementation considerations for libraries, they are more about addressing circular dependencies in code.
Aliasing implementation: while the alias keyword is critical to how easy
or difficult refactoring is, it should be designed on its own.
Compilation details: this proposal sets up a framework that should enable well-designed compilation, but does not set about to design how compilation will work.
File-private identifiers: Something similar to C++ static functions may
exist. However, that will be addressed separately.
Incremental migration and unused imports: incrementally migrating a declaration from one library to another might require an intermediate state where callers import both libraries, with consequent issues. However, it may also not require such. Whether it does, or whether tooling needs to be added to support the specific intermediary state of transitional, unused imports, is out of scope.
Name lookup, including addressing conflicting names between imports and names in the current file: the name lookup design is likely to address this better, including offering syntax that could refer to it if needed.
Package management: while we want to choose syntax that won't impose barriers on building package management into Carbon, we should not make assumptions about how package management should work.
Prelude package, or fundamentals: while we've discussed how to handle name
lookup for things like Int32, this proposal mainly lays out a framework
where options for addressing that are possible.
This proposal should not be interpreted as addressing these issues. A separate discussion of these issues will remain necessary.
Extended open question comparisons may be found in
the examples doc
in addition to the code_and_organization.md alternatives section.
Decision: No.
Right now, the package syntax is very package-oriented. We could instead
eliminate package semantics from code and organization, relying only on
libraries and removing the link to distribution. This is the
collapse the package concept into libraries
alternative.
Does the core team agree with the approach to packages and libraries? If not, does the alternative capture what the core team wants to be turned into the proposal, or is some other approach preferred?
Decision: Make paths correspond to libraries for API files, not impl files.
Keep package.
Right now, the package syntax requires the package's own name be repeated
through code. This touches on a couple alternatives:
packageThe end result of taking both alternatives would be that:
package and library would no longer need to be specified on the
first line.
import would still need a library.package keyword would always be used to refer to the current package.
Software and language evolution:
The syntax and interactions between package and import should enable
moving code between files and libraries with fewer modifications to
callers, easing maintenance of large codebases.
#include updates are avoidable when moving code
around.Code that is easy to read, understand, and write:
By setting up imports so that each name in a file is unique and refers to the source package, we make the meaning of symbols clear and easier to understand.
The proposed namespace syntax additionally makes it clear when the
package's default namespace is not being used.
Clearly marking interfaces will make it easier for both client code and IDE tab completion to more easily determine which APIs can be used from a given library.
Fast and scalable development:
Interoperability with and migration from existing C++ code:
import should enable extending imports for use in
interoperability code.This proposal provides an organizational structure that seems both workable and aligns well with Carbon's goals: