more human readable, but also usually more verbose
some are closer to natural languages
usually abstracts away intricacies of dealing with underlying machine / computer
loosely speaking, meant for programmers
low level
usually terse / less verbose
usually does not look like a natural language
need some knowledge of underlying machine / computer
loosely speaking, meant for machines
Compiled and Interpreted
Two Ways to Execute a Program
Before a program can be executed, the source code of a high-level language must be translated into something that the computer can understand. You can:
compile the source code into another (usually low-level) language using a compiler… then execute
execute the source code immediately using an interpeter
Compiling a Program
when we talk about source code (or just code), we're referring to the program prior to compilation
programs called compilers perform this translation
a compiler parses your source code in order to do this translation
parse - to examine a program and analyze the syntactic structure
we do this for natural languages too!
the result of this translation is usually referred to as object code
the object code is what is run by the computer
Compiling a Program… Continued
General Workflow
Write code
Compile
Execute program
Go back to step #1
Examples of Compiled Languages
Basic
C/C++
Java (there are some subtleties here that we'll talk about later)
Interpreting a Program
a program can be executed using an interpeter
an intpreter is a program that executes source code without the need for compilation
the way that a program is executed behind the scenes varies by language and implementation
perhaps compilation is done behind the scenes
…or the interpreter acts as a virtual machine where the codes just runs
Sometimes an interpeter may also allow a program to be run interactively
also called an interactive shell or an interactive console
DEMO - python interactive shell
DEMO - irb
Interpreting a Program… Continued
General Workflow
Write code
Execute program
Go back to step #1
Examples of Interpreted Languages
Ruby
PHP
Lisp
Compiled vs Interpreted
compiled languages are usually considered faster and more efficient than interpreted languages
interpreted languages are generally thought of as easier to use (less steps, immediate feedback, etc.)
And What Does This Mean for Us?
Despite the pros and cons of compiled and interpreted languages, for our purposes, the main difference between a compiled and interpreted language is:
a compiled language requires an explicit compilation step
before the program can be run.
an interpreted language can be run immediately
Some Important Caveats
distinction is wholly dependent on implementation, not language design
a programming language may be considered compiled, interpreted or even both!
hybrids exist (to further complicate things!)
a language may be compiled to an intermediary form
this form may be run by an interpeter!
still considered compiled because of explicit compilation step
a language may be compiled to an intermediary form that's run immediately by the interpreter