1

Currently reading Steve McConnell "Code complete". "General issues in using variables" chapter, "Binding time" section. He says about variable's binding time in such languages as C++ and Java, that have phases like compiling.

  1. Coding time (use of magic numbers)
  2. Compile time (use of a named constant)
  3. Load time (reading a value from an external source such as the Windows registry file or a Java properties file)
  4. Object instantiation time (such as reading the value each time a window is created)
  5. Just in time (such as reading the value each time the window is drawn)

But is there an alternative for interpreted languages at 2 point? I mean, they also have constants, but they are not compiled. What is their binding time in case of using constants? (JavaScript, Python?)

7
  • 1
    What do you mean by "interpreted language"? Interpretation is not a property of the language, but of the language implementation, i.e. the interpreter (duh). You give JavaScript and Python as examples, but literally every single mainstream implementation of Python (CPython, IronPython, Jython, GraalPython) and JavaScript (V8, SpiderMonkey, SquirrelFish Extreme, Nashorn, dyn.js, GraalJs, Rhino) has a compiler, and there are interpreters for C++ (Cint, Cling, Ch), so how do you define "interpreted language" in a way that excludes C++? Nov 18, 2021 at 9:17
  • Jorg, thank you for your explanation. Could you advice some literature for me to understand that terms more in detail?
    – CoderDesu
    Nov 18, 2021 at 15:24
  • @JörgWMittag, most used approach (and I can sprinkle it with "by order of magnitude"). Nov 19, 2021 at 6:05
  • 1
    @astrowalker: Your comment appears to have been cut off and does not seem to be a grammatically complete sentence, nor am I able to divine its semantics. That may very well be a problem on my end, since I am not a native speaker of English. Would you care to elucidate? Nov 19, 2021 at 7:09
  • @JörgWMittag "so how do you define "interpreted language" in a way that excludes C++? ", me: by using the following criterion -- most used approach... Btw. I don't argue with your point per se, you are correct in your explanation, but it is not terribly useful in non-academic discussion. Nov 20, 2021 at 14:01

1 Answer 1

2

Firstly, Jorg is right but pedantic that compilation and interpretation isn't a property of the language unless it's explicitly specified that way; but nonetheless most languages have a canonical or reference implementation that is either compiled or interpreted, and some languages have features that are difficult to compile unless you ship a copy of the compiler with the runtime (C doesn't have "eval", for example).

Perhaps a more useful way to look at it parse time. For the "magic number" case, the number is encountered directly by the parser and treated as a literal. Whereas the named constant will usually be treated as either a symbol (that is, it's treated as an immutable variable), or a macro (something that is expanded at parse time and converted into a literal).

From that we can make a couple of observations from examples. Python has no true "named constant": it just has variables which by convention the programmer does not change. Original K&R C has no immutable variables either: it has macro expansions which are interpolated into the text of the program before parsing. ("const" was added in C90, but by then the style of the language was already set in the minds of programmers and a lot of old code)

There is an additional wrinkle if you consider that C has three phases, "preprocess", "compile", and "link". There can be variables which are defined as "const" but whose value is not known at compile time, only link time. https://stackoverflow.com/questions/2151831/non-integral-constants/

Certain other languages have pitfalls in which "constants" can be modified, e.g. FORTRAN https://www.ibiblio.org/pub/languages/fortran/ch1-8.html#01

1
  • 1
    Does this answer the question? "What is their binding time?" Is it actually an alternative binding time compared to compiled implementations? Or do you mean to repace 'compile time' with 'parse time' across the board? What difference does this make? Is binding at parse time any 'earlier' or 'later' than compile time in the sense Code Complete discusses? Answering those would make this a great answer.
    – joshp
    Nov 20, 2021 at 17:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.