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

What is the main entry point for execution? Main or Run? #1869

Closed
clavin opened this issue Aug 1, 2022 · 17 comments
Closed

What is the main entry point for execution? Main or Run? #1869

clavin opened this issue Aug 1, 2022 · 17 comments
Labels
leads question A question for the leads team

Comments

@clavin
Copy link
Contributor

clavin commented Aug 1, 2022

Reading through the design documents and looking through the explorer implementation, I've noticed a disconnect between the explorer using Main versus the design docs using Run as the entry point for execution in a Carbon program. I asked in Discord and got some guidance in response:

The entry point being Run over Main hasn't been officially decided, but I [@/josh11b] changed the docs to match what @/chandlerc put in his CppNorth announcement presentation. If there was an official decision from the leads, which you could get by filing a "question-for-leads" issue, it would be good motivation to update either the docs or the explorer to match.

I think it would be great to see a decision made here to motivate cleaning up either the explorer and its test cases or the docs. 🙂

@jonmeow
Copy link
Contributor

jonmeow commented Aug 1, 2022

Note, to offer trade-offs:

Main is closer to C++, and may be more intuitive to developers. It also reflects main use in Java, Python, Rust, and Go.

Run I think was gaining some support because it's more the action ("run an application"). I'm not sure if much cross-language precedent exists: wikipedia notes Xojo.

One reference: https://en.wikipedia.org/wiki/Entry_point

@L4stR1t3s
Copy link

Main because it's the main thread IMO.

@davidzchen
Copy link

I think staying with 'Main' would be better. It is familiar to programmers migrating from C++. Plus, classes that have a 'Run' method aren't uncommon and could cause confusion. 'Main' is unambiguous, especially since in most programs, the 'Main'/'main' name isn't used for any other function.

@zygoloid
Copy link
Contributor

zygoloid commented Aug 9, 2022

We would like to see a proposal discussing the options here and making a recommendation before the leads make a decision. @chandlerc has offered to write one.

@jonmeow jonmeow added the leads question A question for the leads team label Aug 10, 2022
@jonmeow
Copy link
Contributor

jonmeow commented Aug 11, 2022

Filed #2004 to document the need for a proposal.

@cbuteau

This comment was marked as off-topic.

@Tomttth
Copy link

Tomttth commented Aug 15, 2022

I think main functionn would be better and intuitive as novice learners who have exposure to other languages like c c++, java know it is the entry point in that languages. Also the language influencing this(c ++) is using the same.

@KaSSaaaa
Copy link

In my opinion, I think the entry point should be either main like 90% of the languages or "no function at all" like NodeJS or C#.
It could be specified as an entry point at compile time, in a file or based on the file name like main.carbon for example.

@jonmeow
Copy link
Contributor

jonmeow commented Aug 15, 2022

Hi all! We understand there are a lot of opinions about the best choice. However, because this is an issue for leads, we want discussion to focus on providing new information, such as advantages or disadvantages that have not yet been mentioned on this thread, or research that can help with a data-based decision.

As noted in the second comment, we are aware of what other languages do. If you only want to comment in support of a name (e.g., main), please instead use an emoji reaction (e.g., 👍) on a message.

@dustypaws

This comment was marked as off-topic.

@cbuteau

This comment was marked as off-topic.

@cbuteau

This comment was marked as off-topic.

@seanbutler
Copy link

seanbutler commented Aug 29, 2022

In Summary:
The argument for using main is for historical reasons, similarity, ease of access etc and related to a thread based model. The argument for run is that we 'run' applications.

To Counter:

  • Through the above conversation we have referred to the concept under debate as an "Entry Point"
  • The formal shared programming langauge agnostic phrase used is "Entry Point" as given by Wikipedia above
  • The frequency of use of main vs for/while is very low. i.e. a single or small number of mains vs many loops per codebase
  • Neither of the two proposals discussed in this thread are synonyms for the concept at hand.
  • beginners of a language use the entry point a disproportionate number of times compared with mature code bases or experienced devs.

If we already use the term Entry Point to describe the concept and main to reference it in code, should we make the language match the concept? Doing so will also make it more accessible to those new to the language.

Propose:
We select a word that is synonymous with the concept "Entry Point".

Consider:

  • entry
    • entrypoint
    • ent
    • entr
  • begin
  • start

@L4stR1t3s
Copy link

  • entry
  • begin
  • start

These names suggest that the following exists as well:

  • exit
  • end
  • stop

Since they don't, these are not good names for the default entry point IMO.

Further more, it is the entry-point of the main thread, not the entry-point of the application. Lots of things (can) happen before the entry-point is called.

@KateGregory
Copy link
Contributor

Beginners don't know the term "entry point". Beginner programs may contain only one single function (or in languages that insist on it, one single class which holds one single function.) The concept "how does the whatever-it-is-that-runs-your-code know which bit of the code to run?" is not a question that has occurred to them, any more than "which of your heads do you usually wear a hat on?". They may think "I want my application to run" but using that logic to insist that one part of the application be called "run" is not obvious. Words like Entry Point are used by people whose projects have lots of files with lots of classes and functions and understand that one of them should be designated as the starting point.

To me the smart move is to be like the other languages they may know or have been exposed to. That argues for "main" to me.

@github-actions
Copy link

We triage inactive PRs and issues in order to make it easier to find active work. If this issue should remain active or becomes active again, please comment or remove the inactive label. The long term label can also be added for issues which are expected to take time.
This issue is labeled inactive because the last activity was over 90 days ago.

@github-actions github-actions bot added the inactive Issues and PRs which have been inactive for at least 90 days. label Nov 28, 2022
@github-actions github-actions bot removed the inactive Issues and PRs which have been inactive for at least 90 days. label Feb 11, 2023
@chandlerc
Copy link
Contributor

chandlerc commented Mar 1, 2023

I think the leads have arrived at a decision here. We considered both the name of the entry point for execution and the package name that contains it.

Package name: Main
Entry function: Run

I'll trying to document the rationale, but to be very clear I don't think there was an especially strong rationale for these names over some other alternatives. We had quite a few options that were all fine. Each one had a somewhat different set of tradeoffs, but on balance there wasn't a huge reason to pick this option over another.

This is a place where we needed to pick something, and so we did. =]


Should we have a named package with the entry point or an unnamed one? Slight preference for named:

  • While we don't expect it to often be spelled out in the source code, we expect things to need to refer to it such as documentation, error messages, tooling, etc. We could work around it being unnamed, but that seemed slightly more awkward than picking a name.
  • It will also likely be a useful convention to seed for naming the file.
  • Disadvantages:
    • There is a name with special meaning in the language. However, we can pick a name that wouldn't be an effective choice anyways to avoid this.
    • We had to go through the process of picking a name. 🤷
  • There are ways to address these tradeoffs and make omitting a name work fine.
  • This was very borderline with both options seeming fine so as painter I tipped the scales towards named as a matter of preference.

Should we have a verb for the entry point? Slight preference for yes, which eliminated Main as the function name:

  • Verbs read slightly better for functions because they represent an action.
  • We have been trying to use verbs for function names where practical elsewhere in Carbon. This isn't rigid or pervasive, but using a verb here does follow that convention.
  • Disadvantages:
    • The most widely used name for this function in other languages is not a verb, forcing us to invent a name. However, we don't expect matching or differing from this precedent to be a big deal in the grander scheme of things. It seems easy to teach and document this.

Some other function names were considered but rejected:

  • Start -- preferred a word that describes the entire action of the function.
  • Entry, Entrypoint -- same problems as Start combined with being less well discoverable and potentially longer.
  • Exec or Execute -- worried about collision with executing some other program versus the current program and with the exec system call.

Another package name considered was Program, but none of the technical differences were enough to lean in one direction or another. As painter I picked Main with roughly the following rationale:

  • We weren't using Main for the function name, so it seemed available.
  • Given that it is the "main package" and in fact contains the entry point, it didn't seem likely to have any confusion with main functions in other languages.
  • It is shorter than Program.
  • I guess that it will work better to indicate a conventional file name of main.carbon.
  • For folks looking for a main function, it may help them find our version.

I believe @zygoloid is working on a proposal that should document all of this.

zygoloid added a commit to zygoloid/carbon-lang that referenced this issue May 30, 2023
zygoloid added a commit to zygoloid/carbon-lang that referenced this issue May 30, 2023
github-merge-queue bot pushed a commit that referenced this issue Jul 6, 2023
Make the preamble of simple programs more ergonomic, by removing the
`package Main` from the main package and removing the `package`
declaration
entirely from the main source file. Imports within a single package no
longer
need to, and are not permitted to, specify the package name.

Partially covers #2001 / #1136.
Covers #1869.
Supersedes #2265.
Addresses design idea #2323.

---------

Co-authored-by: Jon Ross-Perkins <jperkins@google.com>
Co-authored-by: josh11b <josh11b@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
leads question A question for the leads team
Projects
None yet
Development

No branches or pull requests