01-introduction-part-b-cse216
01-introduction-part-b-cse216
Programming
Abstractions
Dr. Ritwik Banerjee
Computer Science
Stony Brook University
Programming paradigms
Paradigms
Functional OCaml, Haskell, Scheme
Fundamentally, the study of languages (whether programming or natural/human) relies on the same foundational
concepts:
• A language has syntax to specify its structure, and semantics to specify its meaning
• It is absolutely possible that the same syntax can be interpreted according to multiple semantics, yielding
different meanings to the same sentence!
• This happens in programming languages as well as human languages (e.g., Sanskrit has multiple semantics, and
a surface-level sentence may be correct according to more than one grammar).
• A language has features for control and data abstractions
• A language undergoes processing to be interpreted (this ties to semantics)
• A language is designed for comprehension, simplicity, expressiveness, precision, etc.
• This is less common among human languages.
ALGOL (1960)
•free-format syntax, blocks,
type declarations, recursion
Machine languages, •Ideas that gave rise to
assembly languages Modula, and eventually, Java.
Imperative Declarative
• Take the first right turn, walk to the end • My office is room 206.
of the corridor, and take the flight of
stairs to the second floor. Then turn left,
cross 5 doors on your right. The sixth
door is my office.
(and at the level of machine languages, it will
be more like “lift your left leg and swing your
right arm forward, then lift you right leg and
…”, etc.)
A language is interpreted or compiled: difference is how the source code is translated into
machine-readable instructions
• Interpreted languages work by reading the source code in small chunks (lines or blocks),
translating that into machine instructions, and immediately executing it
• This is the default behavior of Python, Ruby, and JavaScript.
• Compiled languages have their source code translated by a compiler into machine code (binary, or
sometimes, some intermediate code); the compiled version of the entire code is executed later.
• This is how languages like C, C++, and Rust work.
• Some languages blur this distinction: Python (.py) first compiles into bytecode (.pyc), which is a
platform-independent intermediate representation; the bytecode is then interpreted by the virtual
machine.