Here Are Some Ways That We Can Describe Programming Languages
INFO - a lot of material, some not in readings… but most important parts are reinforced in readings, of course
Some Characteristics of Programming Languages Include:
high-level and low-level
interpreted and compiled
by paradigm
esoteric and mainstream
High-Level and Low-Level Languages
Low-Level Language
A programming language designed for execution by a computer. (Not so friendly.)
loosely speaking, a computer can only directly execute programs written in low level languages
generally makes no attempt to hide the machinery that it instructs
usually fast and resource efficient
some examples include:
machine code - as close as you can get to the machine
assembly language - just a step above machine code
Low-Level Languages Look Like:
Assembly
Machine Code
High-Level Language
A programming language that is designed to be easy for humans to read and write.
must be compiled or interpreted to a lower-level language so that a computer can execute it
provides abstractions that free the programmer from dealing with the details of the underlying machine
meant for the programmer rather than the computer
usually prioritizes usability over efficiency
more likely to be correct
portable across different operating systems/architectures
Examples of Some High-Level Languages:
Ruby
PHP
QUESTION - (header) what do these examples do?
DEMO - run the program
High-Level vs Low-Level
high level
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