The technical name for the code is not part of any function.

What will be the technical term for scripting code that is not part of any function and is executed first when the script is imported?

For example in python:

import anything #what is the technical name for this code? a = 1 doABackFlip() def myFunction(): #Not this code since it is part of a function b = 2 runSomething() class myClass(): #This is in a class so not this code either 

In javascript:

 <script> //What is the technical name of this code? a = 1 doABarrelRoll() function myFunction() { //Not this stuff. Part of a function again doSomethingCool() } </script> 

I am specifically looking at one or two words for this code. It would be better if it was either a descriptor in general use, or even better, something was invented in some educational article back in the 60s.

+4
source share
2 answers

I’m not sure that the code running outside the functions has a specific name, but the “space” in which they are run has a common name in different languages: it is called the global scope .

Typically, code that runs in a global scope is simply called "code that runs in a global scope."

+1
source

I really like your question, and I can’t give a definitive answer to it. However, I would like to reason a bit here.

When you write a parser for an imperative language, you will come across something like a StatementList - which is a list of statements. So everything inside the surrounding “block” (ie Functions, methods, as well as body of loops or just { and } in other blocks in c-like languages) will be represented as a StatementList . Therefore, the question for me arises: what does the surrounding Node look like in the abstract syntax tree (AST). And for now, all I saw was: "Program."

It is also the name listed on the Pascal list.

+1
source

Source: https://habr.com/ru/post/1483235/


All Articles