Draco-lang / Language-suggestions

Collecting ideas for a new .NET language that could replace C#
75 stars 5 forks source link

[WIP] Declarations and definitions #30

Open WhiteBlackGoose opened 2 years ago

WhiteBlackGoose commented 2 years ago

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

Questions

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.

LPeter1997 commented 2 years ago

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

Binto86 commented 2 years ago

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

jl0pd commented 2 years ago

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