Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[WIP] Declarations and definitions #30

Open
WhiteBlackGoose opened this issue Feb 16, 2022 · 3 comments
Open

[WIP] Declarations and definitions #30

WhiteBlackGoose opened this issue Feb 16, 2022 · 3 comments
Labels
Language idea One single idea which may be a start of a design document
Milestone

Comments

@WhiteBlackGoose
Copy link
Member

WhiteBlackGoose commented Feb 16, 2022

Here I want to make an overview of two things: order of files in a project, order of declared symbols in a file.

Questions

  • Order of files: should the dependency graph of files be a tree, that is, if file A depends directly or indirectly on file B, should B be prohibited from depending directly or indirectly on A?
  • Order of files: if the order matters, should the included files be listed explicitly or automatically detect the order?
  • Order of symbols: can a function reference a symbol defined below in the file? Or maybe the order is the opposite?

C#

There's no order of files in C#. Any symbol within an assembly can reference any other assuming the visibility level allows.

C# Top-level statements

In C# top-level statements the following rules hold:

  1. Any declared symbol can reference any other declared symbol (assuming the visibility allows).
  2. Entrypoint code is in the top of the file.
  3. Functions come strictly after entrypoint code.
  4. Types come strictly after functions.

F#

  1. Order of files matters. Symbols from file A can reference symbols from file B only if B is higher in the hierarchy.
  2. The included files are listed explicitly in MSBuild (it's more of a tooling question perhaps, but it quite relates to the core of the language imo, especially given that MSBuild is the dominant build system for the .net langs).
  3. Within a file, A can reference B only if B is defined above A.
  4. Functions, types and values can be defined in any order within a file.
  5. Each file has some number of modules or namespaces.

OCaml

1, 3, 4 are the same as in F#.

TODO: is it necessary to specify the order of files in OCaml default build system?

  1. OCaml is shipped with ocamlopt which can figure out the correct order of files.
  2. File = module

Rust

In Rust the order of the files doesn't matter, but they form a strong hierarchy based on the file structure. Each folder has a mod.rs, that's essentially the root of the subhierarchy. It declares and marks submodules to be exposed to the outside of this hierarchy. Anything else is basically inaccessible from the outside.

@WhiteBlackGoose WhiteBlackGoose added the Language idea One single idea which may be a start of a design document label Feb 16, 2022
@LPeter1997
Copy link
Member

Note: I've filled in the Rust section so if there's something stupid there, blame me, not Goose!

@WhiteBlackGoose WhiteBlackGoose added this to the 0.2 milestone Jun 2, 2022
@Binto86
Copy link
Contributor

Binto86 commented Jul 15, 2022

I tkink that the c# way would be good: don't care about hierarchy of files or symbols

@jl0pd
Copy link

jl0pd commented Jul 20, 2022

I think that F# way is good. It makes it harder to accidentally make entities mutually recursive. Big projects tend to have dependencies grow extensively and it makes it harder to see actual flow. Rust way is good too, it allows to avoid namespaces like MyNamespace.Something.Internal.SomethingSpecific. Maybe something between will be the best

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Language idea One single idea which may be a start of a design document
Projects
None yet
Development

No branches or pull requests

4 participants