Languages Flashcards
Source Code and Compiler
- “source code” is the high level code authored by the programmer
- the compiler reads the source code and translates and expands it to a larger sequence of machine code instructions to implement the sequence of actions specified by the code
- suppose a “high level” construct, an if-statement, can be implemented by a sequence of 5 machine code instructions
- the output of the compiler is a program file
- end user does not need source code or compiler
- does not work backwords well
Dynamic (Interpreter) Languages
- intrepreter is a program that “runs” other code
- web browsers include a JS interpreter
- proceeds through the code given to it, line by line
Compiler vs. Interpreter Process
- a compiler translates all the source code into equivalent machine code program.exe to be run later – it is a bulk translation.
- an interpreter looks at each line of code, and translates and runs it in the moment, and then proceeds to the next line of source code
- the interpreter does not produce a program.exe, instead it performs the actions specified in the source code directly
Compiler Advantages
- compiled code generally runs faster than interpreted code
- pre-processing the source code, stripping out many complications, leaving the program as lean and direct as it can be to just run
- In contrast, the interpreter deals with each line in the moment, so all the deciphering and overhead costs of interpreting each line are paid as it runs
- these overhead costs in effect make the interpreted program run more slowly than the equivalent compiled program
Dynamic Language Advantages
- tend to have a greater number of programmer-friendly features
- automatic memory management, no programmer input needed
- in contrast, in C and C++, the programmer at times must think about memory management at times, and may have to author lines of code to help solve it
Memory Management
the isssue in a program of knowing, over time, when bytes of RAM are needed and when they can be reclaimed and used for something else
JIT
- “Just In Time” compiler
- best of both compiler and interpreter worlds
- the interpreter is used for simple cases, but for important sections of dynamic code (like the inside of a loop), the JIT creates a block of machine code in RAM for that section
What best describes what a C++ compiler does?
translates C++ source code into machine code
The CPU’s machine code has only simple, low-level instructions. A computer language (such as Javascript) adds high-level features, such as the for-loop we have used. What are some high-level instructions?
- loop over all the pixels in an image
- append two strings together
- print a string to the screen
Firefox is an open source program, so anyone can get access to the source code. What is something that is possible because Firefox is open source?
anyone is free to run the compiler to produce and distribute their own version of Firefox