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

Principle: information accumulation #875

Merged
merged 13 commits into from
Mar 16, 2022
Merged
36 changes: 6 additions & 30 deletions docs/project/principles/information_accumulation.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,23 +43,6 @@ Different languages take different approaches to this problem. For example:
- In Swift, all information from the entire source file is available within
that source file.

It is problematic for the same entity to have different behaviors depending on
which information about it is available. This can lead to a violation of
[coherence](/docs/design/generics/goals.md#coherence) and program consistency.

It is also problematic for both tools and human readers to make information
available prior to its introduction in a source file.

- For a human reader, this violates the literary principle that ideas should
be introduced before they are referenced.
- For a tool, this makes it harder to reason about incomplete or invalid code
for which a prefix is valid, such as frequently happens while editing a
source file, and expands the scope of code that a tool must understand to
correctly interpret code.
- This also makes it harder to use tools such as bisection to determine the
cause of an error, because any part of the source file could contribute to
an error.

## Principle

In Carbon, information is accumulated incrementally within each source file.
Expand All @@ -86,18 +69,6 @@ Disallowing programs from changing meaning in the context of more information
ensures that the program is interpreted consistently or is rejected. This is
especially important to the coherence of generics and templates.

This principle serves several goals:

- [Language tools](/docs/project/goals.md#language-tools-and-ecosystem) should
be easier to write and maintain with information accumulating linearly in
the source file.
- [Language evolution](/docs/project/goals.md#software-and-language-evolution)
options for revisiting this choice are kept open by ensuring that allowing
more information to flow backwards is a non-breaking change.
- [Understandability of code](/docs/project/goals.md#code-that-is-easy-to-read-understand-and-write)
is improved by requiring source files to introduce information before it is
used.

## Applications of this principle

- As in C++, and unlike in Rust and Swift, name lookup only finds names
Expand All @@ -120,4 +91,9 @@ enclosing class, like in C++.

## Alternatives considered

- [Allow information to be used before it is provided](/proposals/p0875.md#strict-global-consistency)
- Allow information to be used before it is provided
[globally](/proposals/p0875.md#strict-global-consistency),
[within a file](/proposals/p0875.md#context-sensitive-local-consistency), or
[within a top-level declaration](/proposals/p0875.md#top-down-with-minimally-deferred-type-checking).
- [Do not allow inline method bodies to use members before they are declared](/proposals/p0875.md#strict-top-down)
- [Do not allow separate declaration and definition](/proposals/p0875.md#disallow-separate-declaration-and-definition)
Loading