0% found this document useful (0 votes)
3 views

01-introduction-part-b-cse216

The document provides an overview of programming paradigms, including imperative, procedural, object-oriented, functional, and logic programming. It explains key concepts such as data and control abstraction, the syntax and semantics of programming languages, and the development of programming languages from early examples like ALGOL and FORTRAN. Additionally, it discusses the differences between interpreted and compiled languages in terms of how source code is processed.

Uploaded by

arshdeeps1805
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

01-introduction-part-b-cse216

The document provides an overview of programming paradigms, including imperative, procedural, object-oriented, functional, and logic programming. It explains key concepts such as data and control abstraction, the syntax and semantics of programming languages, and the development of programming languages from early examples like ALGOL and FORTRAN. Additionally, it discusses the differences between interpreted and compiled languages in terms of how source code is processed.

Uploaded by

arshdeeps1805
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

CSE 216

Programming
Abstractions
Dr. Ritwik Banerjee
Computer Science
Stony Brook University
Programming paradigms

Procedural COBOL, FORTRAN, C


Imperative
Object-
Java, SmallTalk, OCaml
oriented

Paradigms
Functional OCaml, Haskell, Scheme

Declarative Logic Prolog

Constraint Prolog, Mathematica

Ritwik Banerjee © 2025 2


Imperative • Think of imperative programming as a “recipe”, where each step is an
instruction about how to perform the next action, and the next action depends
programming on the current “state” of your kitchen!
• With the exception of reconfigurable computing (like FPGAs), all hardware is
imperative. That is, “what to do” is described in terms of “how to do” it.
• At the lowest level with no abstraction, machine code is imperative.
• Recipe analogy: it will not tell you to chop an onion, it will instead tell you
how to hold the knife and the onion and then how to move the blade of
that knife.
• (Relatively) higher-level imperative languages like C are abstractions of assembly
language, but they follow the same paradigm.
• Recipe analogy: it will still be telling you how to hold a knife and an onion,
but in less excruciating low-level detail.

Ritwik Banerjee © 2025 3


Procedural • A type of imperative programming based on the concept of
procedure calls (COBOL, C, etc.)
programming • The painful low-level details are still there, but the idea is to store
those details away in a separate procedure.
• Recipe analogy: there is a procedure called hold_onion(),
which has the instructions about how to hold an onion; but
you, the programmer who is much more interested in cooking
the overall dish, can simply call that procedure instead of
reading the details about how to grip the onion!
• A procedure is also called a routine, subroutine, function, or
method. Each programming language has its own unwritten
preference of terminology.

Ritwik Banerjee © 2025 4


Object-oriented • Based on the concept of objects, which may contain

programming • data in the form of fields, and


• code in the form of procedures, a.k.a. methods.
• In some languages, fields and methods are together called
attributes, as together they define the properties/behavior of
an object.
• Most OOP languages are based on the idea of a class, and each
object is an instance of a class.
• There are some classless OOP languages (e.g., JavaScript
and Lua). But this course will not cover them.

Ritwik Banerjee © 2025 5


Abstractions Two main categories:
1. Data abstraction focuses on what data is being represented and
how we access and/or modify it, instead of the internal details of
the representation.
• Common data values like integers; and places to store such
values, i.e., variables
• Abstract data types (stacks: we can pop the top element or push
a new top elements, but we may not care about exactly how all
the elements are stored in the stack); this is an abstraction on
the structure of how data is organized
• Related values and structures can be encapsulated together
into program units, e.g., a module, a class, or a package
2. Control abstraction focuses on how various operations or
computations are done, instead of the internal details of how the
data moves
• Statements like x = x + 1
• Control structures like for, while, or if-else
• Procedures, which group together a sequence of actions into a
single action. The main idea is to delegate repetitive and
complex control logic to reusable blocks (this gives rise to
modularity; if you are writing similar logic multiple times, your
code is not modular)

Ritwik Banerjee © 2025 6


Programming languages

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.

Ritwik Banerjee © 2025 7


Development of programming languages

ALGOL (1960)
•free-format syntax, blocks,
type declarations, recursion
Machine languages, •Ideas that gave rise to
assembly languages Modula, and eventually, Java.

FORTRAN (1957) LISP (1960)


•data structures (arrays), •symbolic computation,
control structures (if, do), referential transparency (no
and subroutines. “side effects”), automatic
memory management
•Ideas that gave rise to ML,
Haskell, Scheme, OCaml.

Ritwik Banerjee © 2025 8


A problem
and its
(imperative)
pseudocode

Ritwik Banerjee © 2025 9


Functional programming

• Focus on operations (functions) on data values


• The functions are combined using composition, and
evaluated at specific values using application
• It is common to have no notion of assignments
• Usually, there is extensive use of recursion
• Data is immutable

Ritwik Banerjee © 2025 10


Logic programming

• Focus on relations between data values


• A program specifies “what” must be true about
a problem’s solution; once that is completely
specified, the programming system takes care
of arriving at the solution!
• Declarative programming

Ritwik Banerjee © 2025 11


A “real world” comparison
I am right outside the main entrance of the New
CS building. How do I get to your office?

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.)

Ritwik Banerjee © 2025 12


Language processing

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.

Ritwik Banerjee © 2025 13

You might also like