carbon-lang icon indicating copy to clipboard operation
carbon-lang copied to clipboard

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

Open clavin opened this issue 2 years ago • 15 comments

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. 🙂

clavin avatar Aug 01 '22 18:08 clavin

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

jonmeow avatar Aug 01 '22 20:08 jonmeow

Main because it's the main thread IMO.

L4stR1t3s avatar Aug 01 '22 22:08 L4stR1t3s

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.

davidzchen avatar Aug 02 '22 23:08 davidzchen

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.

zygoloid avatar Aug 09 '22 22:08 zygoloid

Filed #2004 to document the need for a proposal.

jonmeow avatar Aug 11 '22 23:08 jonmeow

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()

cbuteau avatar Aug 13 '22 01:08 cbuteau

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.

Tomttth avatar Aug 15 '22 14:08 Tomttth

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.

KaSSaaaa avatar Aug 15 '22 16:08 KaSSaaaa

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.

jonmeow avatar Aug 15 '22 17:08 jonmeow

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

dustypaws avatar Aug 16 '22 01:08 dustypaws

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 avatar Aug 16 '22 01:08 cbuteau

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.

cbuteau avatar Aug 16 '22 02:08 cbuteau

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

seanbutler avatar Aug 29 '22 11:08 seanbutler

  • 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.

L4stR1t3s avatar Aug 29 '22 11:08 L4stR1t3s

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.

KateGregory avatar Aug 29 '22 20:08 KateGregory

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[bot] avatar Nov 28 '22 02:11 github-actions[bot]

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.

chandlerc avatar Mar 01 '23 03:03 chandlerc