01 Introduction
01 Introduction
Programming
1. Introduction
Federico Busato
2024-03-29
Table of Contents
5 The Course
1/56
About Motivation 1/5
3/56
About Motivation 3/5
4/56
About Motivation 4/5
5/56
www.nytimes.com/2018/12/08/opinion/college-gpa-career-success.html
About Motivation 5/5
twitter.com/bencichy/status/1197752802929364992?s=20 6/56
About Programming 1/2
“You might not think that programmers are artists, but programming
is an extremely creative profession. It’s logic-based creativity”
John Romero, co-founder of id Software
7/56
About Programming 2/2
Form of Art Art is the expression of human creative skills. Every programmer has his
own style. Codes and algorithms show elegance and beauty in the same
way as painting or music
Learn Programming gives the opportunity to learn new things every day,
improve own skills and knowledge
9/56
Learning
10/56
A Little History of
C/C++
Programming
Language
The Assembly Programming Language
main:
.Lfunc_begin0:
push rbp
A long time ago, in a galaxy far, .Lcfi0:
.Lcfi1:
far away....there was Assembly mov rbp, rsp
.Lcfi2:
• Extremely simple instructions sub rsp, 16
movabs rdi, .L.str
liferation .Ltmp1:
.Lfunc_end0:
.L.str:
.asciz "Hello World\n"
11/56
A Little History of C 1/3
In the 1969 Dennis M. Ritchie and Ken Thompson (AT&T, Bell Labs) worked on
developing an operating system for a large computer that could be used by a thousand
users. The new operating system was called UNIX
The whole system was still written in assembly code. Besides assembler and Fortran,
UNIX also had an interpreter for the programming language B. A high-level language
like B made it possible to write many pages of code task in just a few lines of code. In
this way the code could be produced much faster than in assembly
A drawback of the B language was that it did not know data-types (everything was
expressed in machine words). Another functionality that the B language did not provide
was the use of “structures”. The lack of these things formed the reason for Dennis
M. Ritchie to develop the programming language C. In 1988 they delivered the final
standard definition ANSI C 12/56
A Little History of C 2/3
#include "stdio.h"
int main() {
printf("Hello World\n");
} 13/56
A Little History of C 3/3
Areas of Application:
• UNIX operating system
• Computer games
• Due to their power and ease of use, C were used in the programming of the
special effects for Star Wars
14/56
Star Wars - The Empire Strikes Back
A Little History of C++ 1/3
The C++ programming language (originally named “C with Classes”) was devised
by Bjarne Stroustrup also an employee from Bell Labs (AT&T). Stroustrup started
working on C with Classes in 1979. (The ++ is C language operator)
The first commercial release of the C++ language was in October 1985
15/56
A Little History of C++ 2/3
17/56
About Evolution
18/56
Areas of Application
and Popularity
Most Popular Programming Languages
(IEEE Spectrum - 2022)
19/56
Interactive: The Top Programming Languages 2022
Most Popular Programming Languages (TIOBE - December. 2022)
20/56
www.tiobe.com/tiobe-index/
Most Popular Programming Languages (Redmonk - June, 2022)
21/56
redmonk.com
Why C++ is so Popular? 1/2
• Maturity. C++ has a 40 years history. Many software problems have been
already addressed and developing practices have been investigated 23/56
Areas of Application 1/2
* The flight code of the NASA Mars drone for the Perseverance Mission, as well as the Webb
telescope software, are mostly written in C++ github.com/nasa/fprime, James Webb Space
25/56
Telescope’s Full Deployment
Why C++ is so Important?
26/56
An Important Example... (AI Evolution)
27/56
Performance 1/4
N-BODY SIMULATION
P R O G R A M M I N G L A N G UA G E S P E R F O R M A N C E C O M PA R I S O N
900
780
800
700 660
Execution TIme (S)
600
500
400 360
300
300
200
100 21.47 21.96 22.1 26.61
8.23
0
C++ GO SWIFT JAVA Node.js PHP Ruby Perl Python3
Programming Language
28/56
Performance 2/4
29/56
A programming language benchmark
Performance 3/4
30/56
”A New Golden Age for Computer Architecture“, J. L. Heneessey, D. A. Patterson, 2019
Performance 4/4
Hello World
Language Execution Time
C (on my machine) 0.7 ms
C 2 ms
Go 4 ms
Crystal 8 ms
Shell 10 ms
Python 78 ms
Node 110 ms
Ruby 150 ms
jRuby 1.4 s
31/56
Time to "hello world" on my machine
Performance/Expressiveness Trade-off
100,000
10,000
1,000
100
10
1
Assembly C C++ Java JS Python
32/56
Memory Usage
34/56
Energy Efficiency across Programming Languages
CO2 Production
35/56
The Ecological Impact of High-performance Computing in Astrophysics, Nature
C++ Philosophy
C++ Philosophy - Performance 1/3
40/56
C++ Weaknesses
Why C++ is so Difficult? 1/2
... and why teaching C++ as first programming language is a bad idea?
C++ is the hardest language from students to master
• More languages in one
- Standard C/C++ programming
- Preprocessor
- Object-Oriented features
- Templates and Meta-Programming
• Huge set of features
• Worry about memory management
• Low-level implementation details: pointer arithmetic, structure, padding,
undefined behavior, etc.
• Frustrating: compiler/runtime errors (e.g. seg. fault) 41/56
Why C++ is so Difficult? 2/2
“The problem with using C++...is that there’s already a strong ten-
dency in the language to require you to know everything before you can
do anything”
Larry Wall, Creator of the Perl language
Backward-compatibility
“Despite the hard work of the committee, newer features sometimes have flaws
that only became obvious after extensive user experience, which cannot then be
fixed”
“C++ practice has put an ever-increasing cognitive burden on the developer for
what I feel has been very little gain in productivity or expressiveness and at a huge cost
to code clarity”
43/56
C++ Weaknesses 2/2
• Carbon Language
44/56
C++ Alternatives: Rust
Rust (1.0, 2015) has been Stack Overflow’s most loved language for eight years in a
row. Rust focuses on performance and zero-abstraction overhead as C++. It is
designed to prevent many vulnerabilities that affect C++, especially memory bugs,
enforcing constraints at compile type. In addition, it promotes cross-platform
compatibility
1
Grading on a Curve: How Rust can Facilitate New Contributors while Decreasing
Vulnerabilities
• CISA, NSA: The Case for Memory Safe Roadmap
• Octoverse: The Fastest Growing Languages
45/56
• Secure by Design: Google’s Perspective on Memory Safety
C++ Alternatives: Zig
• Ecosystem. Lack of tools and libraries developed in the last four decades
1 47/56
Bjarne Stroustrup: Delivering Safe C++
Why Switching to a New Language is Hard? 2/3
49/56
Language Complexity
50/56
The Course
The Course
51/56
The Course
For many topics in the course, there are more than one book devoted to present the
concepts in detail
52/56
The Course
The primary goal of the course is to drive who has previous experience with
C/C++ and object-oriented programming to a proficiency level of (C++)
programming
• Proficiency : know what you are doing and the related implications
• Understand what problems/issues address a given language feature
• Learn engineering practices (e.g. code conventions, tools) and hardware/software
techniques (e.g. semantic, optimizations) that are not strictly related to C++
What the course is not:
• A theoretical course on programming
• A high-level concept description
Organization:
• 22 lectures
• ∼1,500 slides
• C++03 / C++11 / C++14 / C++17 / C++20 / (C++23) / (C++26)
Roadmap:
• Review C concepts in C++ (built-in types, memory management, preprocessing,
etc.)
• Introduce object-oriented and template concepts
• Present how to organize the code and the main conventions
• C++ tool goals and usage (debugger, static analysis, etc.)
54/56
Who I Am
• Research/Work interests:
- Linear Algebra
- Graph Algorithms
- Parallel/High-Performance Computing
- Code Optimization
Our projects:
cuSPARSELt Specialized library for sparse matrix-matrix multiplication that exploits the
most advanced GPU features such as Sparse Tensor Cores
Richard P.
Feynman
56/56
“The only way to learn a new pro-
gramming language is by writing pro-
grams in it”
Dennis Ritchie
Creator of the C programming language
56/56