carbon-language / carbon-lang

Carbon Language's main repository: documents, design, implementation, and related tools. (NOTE: Carbon Language is experimental; see README)
http://docs.carbon-lang.dev/
Other
32.28k stars 1.48k forks source link

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

Closed clavin closed 1 year ago

clavin commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

Main because it's the main thread IMO.

davidzchen commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

Filed #2004 to document the need for a proposal.

cbuteau commented 2 years ago

Main because it's the main thread IMO.

This by far is the best argument ever. How often have you renamed your thread handlers so in the debugger they appear as this. Main() MessageProcessing() StateProcessing()

Tomttth commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

Call it 'master' for a perfect storm! It's PR...🤷‍♂️

cbuteau commented 2 years ago

Call it 'master' for a perfect storm! It's PR...🤷‍♂️

Is it? maybe it is the reckoning.

Metallica: Master of Puppets (Official Lyric Video) https://www.youtube.com/watch?v=6xjJ2XIbGRk

Sorry just saw a killer Metallica Cover Band.

cbuteau commented 2 years ago

main Main MAIN other stupid spellings.

Why familiarity? From very early on of coaching greens I have told many. Find the Main Entry Point where execution starts.

Why else Discussions of the main thread versus the other threads do not lose context. https://stackoverflow.com/questions/14593881/any-difference-between-main-thread-and-other-threads

run Run RUN

Be a little different and stand out.

execute Execute EXECUTE

Again mostly to be different

Master MASTER

To start fresh all discussions. What is the Master thread to all threads. Why is the Master thread always responsible for the UI.

The way I see it you either go with main() or something of a revolution. Or you could just go with main and provide a compile option for starters.

Good luck but I think people will continue to comment on this thread.

seanbutler commented 2 years ago

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:

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:

L4stR1t3s commented 2 years ago
  • entry
  • begin
  • start

These names suggest that the following exists as well:

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 commented 2 years ago

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[bot] commented 1 year ago

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.

chandlerc commented 1 year ago

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:

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

Some other function names were considered but rejected:

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:


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