Main File

Unlike other object-oriented programming languages, JS++ does not have a "main method" per se. Instead, the JS++ compiler infers the application entry point to be the file where A) the dependency graph begins and B) is not defined as a module.

In simpler terms, it is a file that does not define a module (via the module keyword). However, it can still import as many modules as it may need. The following basic Hello World program can be a "main file":

1
2
3
import System;
 
Console.log("Hello World");

This simple file, which we will name Hello.jspp, does not define a module. However, it does import a module (the System module). Therefore, we can say Hello.jspp "depends on" System. The dependency graph therefore begins at Hello.jspp. This qualifies Hello.jspp as an application entry point as it satisfies both the conditions where A) it is the file where the dependency graph begins, and B) it is not defined as a module.

In contrast, the following code would not qualify as being a main file because it is defined as a module:

1
2
3
4
5
6
7
8
9
10
11
12
import System;
 
module MyModule
{
    class MyApplication
    {
        public MyApplication()
        {
            Console.log("Hello World");
        }
    }
}

Notice the presence of the module keyword at line 3. When the module keyword is used, we are defining an importable module. However, code for an importable module cannot simultaneously be a main file.

Variables declared in the main file at the top-level scope are not globally-scoped. In fact, there is no concept of a "global scope" per se in JS++. Instead, variables declared in the main file are scoped to the main file itself (via a "file scope"). For more information, see the documentation on scopes.

The terminology "main file" is favored since there is no "method" (e.g. the main "method") per se. Note that there can technically be multiple possible "main files" in a single directory; it is your job to ship the correct one.

See Also

Share

HTML | BBCode | Direct Link