Programming: Find and describe an automated
process that solves a given problem.
How to knowledge.
Coding: Translate a process into a
language the computer can understand
Coding is cheap (especially in the era of gen AI),
programming isn’t! Or is it? While coding, many things
happen in your brain! Coding can not really be reduced to “typing
characters on a keyboard”. Nevertheless, writing code is a part of a
broader activity we call programming
“Computer science is a terrible name for this business… First of all,
it’s not a science… It’s also not really very
much about computers” (Harold Abelson, MIT
6.001 Structure and Interpretation, 1986). Watch the first episode
of this course to have a wonderful introduction to programming
Programming is about processes, building how-to
knowledge.
If their birth date is more recent
than the previous youngest person’s (or if it’s the first person we
ask), consider this person the youngest person in the
group.
We have to remember “somehow” whose birth date is
the most recent and which person is the youngest
during the process, in order to give the correct answer at the
end: we need memory.
We need to namedata to identify them
correctly.
Let’s do this again using a piece of paper as
memory, to keep track of the correct answer.
Take a piece of paper and writenone for “Youngest Person” and “Birthdate”.
For each person in the group:
Ask for their birth date and their name.
If their birth date is more recent than the
one written on the paper (or if it’s the first person),
update the paper: erase the old info
and write down this new person’s name and birth
date.
Show the name written on the paper.
Find the
youngest person program, a graphical view #
This is what we can call Pseudo-code or Structured
english (For each, If, Update, Erase, etc.). This program can
not be (yet!) executed by a computer, because computers does
not speak english
Our piece of paper = memory (read and write to
it)
Youngest Person and Birthdate are what we
call variables:
They have a name (unique identifier)
They store some dataduring the
process
Our procedure
has two parts: Data and Instructions #
bg right contain
Notice that our program is made of two different
parts:
Data: “Birth Date”, “Name” are data. It’s facts,
information, values. It doesn’t do
anything.
Actions/Instructions: “For each”, “if”, “update the
paper”, “ask for” are instructions, actions to perform.
Instructions are executable.
Once figured it out, we can code (encode, translate)
this procudreinto a programming language,
like the Python language (or any other language!), to
automate its execution with a
computer.
An automated procedure is what we call a
program.
Any program can be encoded into different
programming languages
Computers are electronic machines able to execute
very simple operations
Computers only understand binary code, called
Machine code
Machine code is binary patterns that encodes signals for the
hardware to activate specific circuits and execute specific
actions (Read, Write, Add, Compare, etc.). This correspondence is
called the Instruction Set Architecture (ISA)
Each machine (CPU) has its own Instruction Set.
Ex: 00010101 10110101 machine code for a given machine
could result in the action “write the value
to memory” or “compare 72 to 16”.
Von
Neumann Architecture is based on a core principle: data and
programs are stored in the same main memory (in binary)
Von Neumann architecture remains the standard computer
architecture used today!
Prior, machines required physical rewiring to switch
programs (One problem to solve = One machine). The Von Neumann
architecture allows computers to run any program simply by loading new
binary instructions into memory! This is Software!
Fundamental architecture: modern computers
still follow the Von Neumann model (a single memory for both
data and instructions, a processing unit and a control unit);
How we program machines: our programming
languages and concepts remain
nearly unchanged, even though hardware has evolved
drastically.
^ -> Python, PHP, Lisp, Java, R, Fortran, etc.
| ----------------------
| Higher level languages (closer to humans)
| ----------------------
| - C Language : on the border between lower and higher level languages
| ---------------------
| Lower level languages (closer to hardware)
| ---------------------
| - Assembly languages (last human readable programming language before binary)
| - Machine code (just bits)
Hardware details are exposed (CPU architecture, registers, memory
addresses). Memory is managed explicitly. Perfect for embedded systems.
Examples: Assembly languages, C/C++ (from a modern perspective).
Pros:
Performance and optimization: Direct control over
execution speed and resource usage (Manual Memory
Management)
What you write is (almost) directly what the hardware executes
Abstract away hardware details. Focus on
problem-solving logic rather than how the
computer works (CPU, RAM). Examples: Java, JavaScript, Lisp,
Python!, etc.
Pros:
“Closer” to the problem to solve, stronger
abstractions (loops, data structures, procedures/functions,
modules, etc.), more human friendly
Portability: Write once, run anywhere
(cross-platform*).
Automatic Memory Management via Garbage
Collection and automatic allocation.
Compiled languages : the entire high-level program
is transformed directly into Machine Code
(01001000...) by a compilerprior
to running. Produces an executable file tailored directly to the CPU
instruction set, yielding maximum execution performance and determinism.
Examples: C, C++, Fortran, Go, Rust
Interpreted languages : a pre-compiled
program, called an interpreter, reads and
translates code line by line into intermediate code
(bytecode), executing instructions dynamicallyon the fly. Offers flexibility and ease of development, but
adds a translation layer above hardware execution and requires to load
the interpreter in memory. Examples: Lisp, PHP, JavaScript, Python
We need to learn its language syntax. It will be our
vessel to explore programming.
Syntax changes slightly from one language to another,
concepts and fundamentals don’t! Without knowing, by
learning Python, you will be learning many other languages at the
same time!
Programs are written in files called scripts, with a
.py extension (by convention).
To run a program, we only have to call the Python
interpreter (Play button in PyCharm):
# In the terminal, inspect Python version installed (3+)python-VPython 3.14.7# Run a program written in my_program.pypython my_program.py
Be sure to be able to master the full cycle:
write/read code, run your program, see the output
Our
“Find the youngest person in the group” program… in Python #
Disclaimer:
Try to get the big picture of the following code (the
different parts and the role of each section)
There are a lot of details! It’s completely normal if you
don’t understand everything for now, don’t worry!
At the end of the next module you will be able to write such
programs yourself!
Run “Find the
youngest person in the group” program #
Copy/Paste the program in a new script
called find_youngest.py
Run it in PyCharm and check the
result in the terminal
group = {"Alice": "1995-04-12","Bob": "2002-11-23","Charlie": "1988-08-05",}youngest_name =Noneyoungest_date =Nonefor name, date_str in group.items():if youngest_date isNoneor date_str > youngest_date: youngest_name = name youngest_date = date_strprint(f"The youngest person is {youngest_name}, born on {youngest_date}.")
Explain something (a concept, a copy/paste piece of
code)
Debug some code
Don’t use it to code/work for you ! Writing code
has never been the problem
You must be able to Understand,
Explain and Modify your code
without AI. You are responsible of
your code and what it does.
Make mistakes. In programming, you can test
your understanding by executing your program!
You will make mistakes and that’s ok. A (good) program is
written iteratively.
Don’t worry, you will have PLENTY OF TIME to be productive in
your (future) job! We are here to LEARN, not
to be productive.
Learning space: Learn by making
mistakes, Receivefeedback, Do
things manually, Use simple or specialized tools, Work on
small-scale problems and systems, Follow
provided specifications (labs, exams, projects)
Production space: Gather
requirements, specify a solution, Respect
constraints (deadline, budget) and tradeoffs (quality/cost),
Communicate, Use more complex environments and
tools, Take responsibility, Deliver, Deploy to
production, Monitor, Maintain, Work on large and complex
systems
Von Neumann has made major contributions to quantum
mechanics, functional analysis, mathematical logic, quantum logic,
computer science, economics, etc! He also participated in U.S. military
programs (Manhattan
Project).
The difference comes down to when variable types are
checked: at compile time (before running) or at runtime (while
running).
Statically Typed languages:
Types are associated with variables and
determined at compile time. Once a variable is declared
as an integer, it cannot hold a string. Examples: C, C++, Java, Rust,
Go, Swift.
Compilers can detect errors before running the
program (at compile time)
Dynamically Typed Languages :
Types are associated with values, not variables,
and checked at runtime. A single variable can hold an
integer, then a string, then a list, etc. Examples:
Python, JavaScript, Ruby, PHP.
Faster to write, with less boilerplate code. Ideal for rapid
prototyping.
Type errors cause crashes while the program is
running!
Python IS a (strong) dynamically typed language
Demonstration:
from high level code to binary code in C #
Compilation of a C program with gcc compiler.
High level C code (main.c)
After compilation (cc -S main.c), assembly
code (main.s)
After assembling (cc main.c), binary
code (a.out). See binary code in hexadecimal
format with hexdump -C a.out