- Communication
- Problem solving/decomposition
- Functional programming (FP)
- pure functions
- side effects (FP doesn't want them!)
- higher order functions
- monads
- category theory
- Imperative, Structural, and Procedural programming
- See https://softwareengineering.stackexchange.com/questions/117092/whats-the-difference-between-imperative-procedural-and-structured-programming
Consider the difference between:
- Bash command to run a Python script which takes multiple file name arguments:
python script.py file1.txt file2.txt file3.txt
- Bash command which runs a Python script multiple times:
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ cat countdown_recursive_debug.py | |
def countdown(n): | |
print(f"DEBUG: enter countdown({n})") | |
print(n) | |
if n > 1: | |
countdown(n - 1) | |
print(f"DEBUG: exit countdown({n})") | |
countdown(5) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ cat countdown_iterative.py | |
def countdown(n): | |
while n > 0: | |
print(n) | |
n -= 1 | |
countdown(5) | |
$ python3 countdown_iterative.py | |
5 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ cat countdown_recursive.py | |
def countdown(n): | |
print(n) | |
if n > 1: | |
countdown(n - 1) | |
countdown(5) | |
$ python3 countdown_recursive.py | |
5 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[ | |
{ | |
"id": "0001", | |
"type": "donut", | |
"name": "Cake", | |
"ppu": 0.55, | |
"batters": | |
{ | |
"batter": | |
[ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ python quiz.py | |
Birdman (film) | |
What year was Birdman released? | |
A. 2015 | |
B. 2014 | |
C. 2000 | |
D. 1978 | |
Enter Answer(s): ab |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
class ObjectEncoder(json.JSONEncoder): | |
def default(self, o): | |
return o.__dict__ | |
class Address: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class QuestionA: | |
def __init__(self, question_dict): | |
self.question_dict = question_dict | |
class QuestionB: | |
def __init__(self, question_text, answer_dict): | |
self.question_text = question_text | |
self.answer_dict = answer_dict | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sqlalchemy import Table, MetaData, Column, Integer, String, ForeignKey, Date, DateTime, Numeric, Interval, Text | |
from sqlalchemy.orm import mapper | |
from sqlalchemy import create_engine | |
from sqlalchemy.orm import sessionmaker | |
from pathlib import Path | |
import sqlite3 | |
metadata = MetaData() | |
credit_card_offer = Table('credit_card_offer', metadata, |