Hello World
Hello World
Hello World
High level concept for structure & implementation of
computer programs and programming languages.


👉 imperative programming
a sequence of steps (like a cookbook)
Programming Paradigms work by taking freedoms away.
let’s try that

.global _start
.align 4
_start:
mov x5, #3 // initialize counter with 3
loop:
bl print_hello
sub x5, x5, #1 // subtract 1 from counter
cmp x5, #0 // check if counter is 0
bne loop // else, go to loop
b exit // go to exit
print_hello:
mov x16, #4 // syscall 4 == write
mov x0, #0 // 0 == stdout
adr x1, hello
mov x2, #13
svc #0x80 // perform syscall
ret
exit:
mov x16, #1 // syscall 1 == exit
mov x0, #0 // exit code 0
svc #0x80 // perform syscall
hello: .ascii "Hello World\n"
go to statement considered harmful (1968)
👉 structured programming
reduces freedom of control flow
use if, for, while etc… instead of jumps
(FORTRAN (1955) was unstructured…)
Use procedures that can be called to modularize code.
Some definitions overlap between procedural and structured programming.
Discovered in 1966 with the creation of Simula-67 language.
The idea of polymorphism removes the need for function pointers.
I’m sorry that I long ago coined the term “objects” for this topic because it gets many people to focus on the lesser idea. The big idea is “messaging”.

Appeared in 1957, with the Lisp programming language, the first functional language.
Functional programming removes assignment 😱.
👉 no side-effects
Actually, Lambda Calculus was already formulated in the 30ies.
[1,2,3,4,5]
Independent of language, it’s good to know about the ideas.
In many cases, you’ll want to combine ideas.
Languages are influenced by paradigmns.
It’s ok to have preferences though…
| paradigm | year |
|---|---|
| structured | 1968 |
| object oriented | 1966 |
| functional | 1957 |
(of course there are many more)
How to achive it?
What to achieve?
In the last 15 years, most of the imperative languages gained some level of support for declarative concepts. Python supports both approaches.
ds2 = ds1.assign(tas=compute_tas())The same code can invoke different actions.
Back to Alan Kay:
The big idea is “messaging”.
Bundle together data and member functions inside an object, while limiting direct access to the state.
Used to hide complexity and increase code correctness.
Many OO languages support inheritance: a class can inherit features from a parent class
classDiagram
class Book
Book : +int page_count
Book : +int get_page_count()
class EBook
EBook : +string url
EBook : +string get_url()
Book <|-- EBook
Used to increase code reusability and avoid code duplication
Define a book class
Person with a constructor which initialises name and address attributesStudent that extends Person and sets a university attributeAlice and student Bobself.address with self.__address. What happens?Algorithms with work for any (or many) types.
Revisit the power function.
Closures allow functions to access and manipulate variables that are defined outside their scope
Closure example
\(h = g(2)=f(1)(2) = (\lambda y : 1 + y)(2) = 1 + 2 = 3\)
More on lambda functions.
Higher-order functions can take functions as arguments and/or return other functions.
Pure functions have no side effects
An example of how to use immutable data structures can be found here.
Write a higher-order function using map/filter/reduce which returns the product of the squares of the positive values from the input array
pow, exp, etcA lambda function is an anonymous function defined in-place.
Lambda function
It can be :
When using xarray.Dataset make sure your function does not change the input data
Better alternative would be:
Take the example from the hands-on session on functional programming using map/filter/reduce and rewrite it using idiomatic numpy. Explain how this numpy code relates to the Python implementation using map/filter/reduce. Why can numpy boost performance and why is the way that numpy is implemented so useful?
For those who don’t know numpy yet, have a look here: numpy for beginners
Next week we will randomly select some participants to present and discuss their solutions.