(OOP2024) Lecture 1 - Programming Languages History and Paradigms
(OOP2024) Lecture 1 - Programming Languages History and Paradigms
Lecture 1:
Programming Languages:
History and Paradigms
Po-Chun Huang (黃柏鈞)
1
Agenda
• History of computers
• History of programming languages
• Programming paradigms
2
History
3
https://i.ytimg.com/vi/WZcISqf5_6w/hqdefault.jpg
Inventor of The First Digital Computer
4
https://www.britannica.com/biography/Charles-Babbage; https://en.wikipedia.org/wiki/Charles_Babbage
The First Digital Computer
• Babbage’s analytical machine (c.
1840) is the first digital computer
in history.
5
https://www.pinterest.com/pin/450148925239734298/; https://en.wikipedia.org/wiki/Analytical_Engine#/media/File:Babbage_Analytical_Engine_Plan_1840_CHM.agr.jpg
How Powerful Is the First Digital Computer?
6
https://en.wikipedia.org/wiki/Analytical_Engine; https://en.wikipedia.org/wiki/Analytical_Engine#/media/File:PunchedCardsAnalyticalEngine.jpg
The First Programmer
• Ada Lovelace (1815–1852) is the
first programmer in history.
• The programming language Ada is
named after her.
7
https://www.britannica.com/biography/Ada-Lovelace
The First “Bug” in History
• In 1944, the rear admiral Grace
Hopper (1906–1992) found
the first (physical) computer
bug in Harvard Mark II
computer in history.
8
https://zh.wikipedia.org/wiki/%E8%91%9B%E9%BA%97%E7%B5%B2%C2%B7%E9%9C%8D%E6%99%AE; https://www.thoughtco.com/howard-aiken-and-grace-hopper-4078389; https://www.britannica.com/biography/Grace-Hopper
Generation of Computer Programming Languages
• Gen 1 (low-level): Machine language.
• Gen 2 (low-level): Assembly languages.
• Gen 3 (high-level): C, C++, Java, Visual Basic and JavaScript.
• Gen 4 (with natural language-like syntaxes): Perl, Python, Ruby, SQL,
MatLab (Matrix Laboratory).
• Gen 5 (with visual tools): Mercury, OPS5, and Prolog.
9
https://www.geeksforgeeks.org/generation-programming-languages/
Computer Programming Paradigms
• Imperative
• Procedure
• Object-oriented (OO)
• Declarative
• Functional
• Logic
• Mathematical
• Reactive
10
Imperative Programming
• With imperative programming, a program consists of a
number of statements that command the computer to do
something.
• Examples
• cout << “Hello, World!\n“;
• int i = 5, j = 8;
• i++;
• i = j + 3;
• int k = max( i, j );
• fprintf( fp1, “Hello, World!\n" ); 11
Functional Programming (FP)
• In contrast to imperative programming, functional
programming (FP) tells the computer what kinds of
solutions are needed.
• Programming languages that support FP: Haskell, Scheme,
ML, Ocaml, Scala, Erlang, LISP, R, and Mathematica.
• Example ‒ Imperative version ‒ Functional version
a = 0 def increment(a):
def increment(): return a + 1
global a
a += 1
12
https://maryrosecook.com/blog/post/a-practical-introduction-to-functional-programming
Structural Programming
• Structural programming splits large programs into
functions, code blocks, while and for structures to avoid
spaghetti code.
• Better code
• Spaghetti code for computing squares
for( i = 1; i < 10; i++ )
int i = 0; cout << i << " sqr = " << i*i;
REPEAT: i++;
cout << " Done.\n";
cout << i << " sqr = " << i*i;
if( i >= 10 ) goto DONE;
goto REPEAT;
DONE: cout << "Done.\n"; • Goto statements are considered
harmful. Really?
13
https://zh.wikipedia.org/wiki/%E9%9D%A2%E6%9D%A1%E5%BC%8F%E4%BB%A3%E7%A0%81
Structural Programming (Cont’d)
• Structures in structural programming
• Sequence: normal statements ran one by one.
• Selection
• if…then…else
• switch…case
• ?:
• Repetition
• for
• while…
• do…while…
17
https://www.tiobe.com/tiobe-index/
We Use C++ in This Course. But Why?
• C++ has the best popularity (if calculated together with its
predecessor, C).
• C++ provides more direct control of computer hardware.
• C++ is well defined by the advancing ISO standards.
• C++ has an open community, not owned by proprietary
companies.
• C++ has many free and excellent software tools.
• Abundant online resources for troubleshooting.
• Python has a similar (and simpler) syntax to C++.
18
History of C++
•Combined programming language (CPL) (1963)
Basic CPL (BCPL) (1967)
B (1969)
C (1972)
C++ (1983)
•Although C# seems C++++, it is not a successor of
C++.
19
C++ Is an Ever-evolving Language
20
https://isocpp.org/files/img/timeline-2022-07.png
Code Segment for “Max” in CPL
Max(Items, ValueFunction) = value of
§ (Best, BestVal) = (NIL, -∞)
while Items do §
(Item, Val) = (Head(Items),
ValueFunction(Head(Items)))
if Val > BestVal then (Best, BestVal) := (Item,
Val)
Items := Rest(Items) §⃒
result is Best §⃒
21
https://en.wikipedia.org/wiki/CPL_(programming_language)
Code Segment for “Factorial” in BCPL
GET "LIBHDR"
LET START() = VALOF $(
FOR I = 1 TO 5 DO
WRITEF("%N! = %I4*N", I, FACT(I))
RESULTIS 0
$)
AND FACT(N) = N = 0 -> 1, N * FACT(N - 1)
22
https://en.wikipedia.org/wiki/BCPL
Code Segment for “Base Conversion” in B
printn(n, b) {
extrn putchar;
auto a;
if (a = n / b) /* assignment, not comparison */
printn(a, b); /* recursive */
putchar(n % b + '0');
}
23
https://en.wikipedia.org/wiki/B_(programming_language)
Code Segment for “Fibonacci Series” in C
#include <stdio.h>
int main() {
int i, n, t1 = 0, t2 = 1, nextTerm;
printf("Enter the number of terms: ");
scanf("%d", &n);
printf("Fibonacci Series: ");
for (i = 1; i <= n; ++i) {
printf("%d, ", t1);
nextTerm = t1 + t2;
t1 = t2;
t2 = nextTerm;
}
return 0;
}
24
https://www.programiz.com/c-programming/examples/fibonacci-series
Imperative Programming: A Closer Look
25
Procedural Programming: A Closer Look
26
Thank You Very Much!
Q&A?
27