3

The term compile time is used with compiled languages (such as C++) to indicate the point in which source code is going through the compilation process.

The term runtime is used to indicate the point in which the application is opened and being run by a user.

If, for example, we wrote a simple game that rendered terrain based on some list of vertices... if this terrain data was fetched from a server, I might say that the state of the terrain is unknown until runtime. However if it was envisioned that we'd only have one terrain 'model,' and configured that directly in the source code, I might say the state of the terrain is known at compile time (would I be wrong in saying this?).

In Javascript, what would the equivalent terminology be for compile time? My own solution was to call it design time, however I'd be interested to know if there is correct terminology for this.

sookie
  • 2,437
  • 3
  • 29
  • 48
  • 1
    Since JavaScript is an interpreted language, not a compiled language, **`execution time`** would be a proper equivalent in JavaScript (imo). – AndrewL64 Jun 22 '18 at 11:29
  • I would think, since there is nothing to compile, it would just be the `load time` of the script – Sudipta Mondal Jun 22 '18 at 11:46
  • If you have a build step that bundles the data into the code, it's definitely valid to say it's a *compilation step*. – Bergi Jun 22 '18 at 11:48
  • Depends on the implementation, but some engines have "just in time" (JIT) compilation. See https://stackoverflow.com/q/7807235/691711 – zero298 Jun 22 '18 at 13:17

3 Answers3

1

It might make more sense, in the case of your example, to just say that it is 'hard-coded', as this seems to be more accurate for what you are describing. Things that are hard-coded are always known at compile-time, but things known at compile-time are not necessarily hard-coded (in C++, for example, they can be generated with constexpr functions, or injected using build parameters).

The closest thing to 'compile-time' in Javascript I would probably call 'build-time', as you often have some sort of building step in Javascript, whether this a heavyweight build process using WebPack, just simple minification, or even just collecting a particular version of your application's files into some sort of distributable package. Even if you're not actually performing such a step at all, I think people would generally understand what was meant by this.

Sean Burton
  • 907
  • 7
  • 15
0

Depends on the implementation, but some engines have "just in time" (JIT) compilation. See JavaScript Just In Time compilation.

However, the things that you can do as the code writer, rather than the engine, are mostly limited to bundling and minification to reduce fetching all of the scripts that are needed to run your program.

The closest comparison would likely be how you can dynamically and statically link in compiled languages.

zero298
  • 25,467
  • 10
  • 75
  • 100
0

There is no real equivalent to "compile time" in Javascript.

A common term to refer to e.g. "hoisting" or variable declarations without an assigned value is "creation phase" (vs. "execution phase").

This works well to explain and understand javascript. However, there not necessarily really is such a specific "phase" happening.

The Language Specification ECMA-262 doesn't use these terms either. Instead, it only uses relative terms, i.e. it specifies what should happen before or after something else, and apparently leaves the implementation to the engine developers.

E.g. commonly explained in the internet in a way like:

a var is declared in the "creation phase", and instatiated in the "execution phase"

But ECMA only specifies it more like this way:

a var (/let/const/...) is created when X, but stays 'undefined' as long as Y, ... (but may not be accessed until Z, ...)

Examples for such relative terms:

ECMA-262, 11th, chapter 13.3.2:

Var variables are created when their containing Lexical Environment is instantiated ...
... is assigned the value ... when the VariableDeclaration is executed, not when the variable is created

ECMA-262, 11th, chapter 8.1:

a new Lexical Environment is created each time such code is evaluated

kca
  • 4,856
  • 1
  • 20
  • 41