Chapter 2 B1U4 Functions

This is supplementary material for the corresponding lesson from Python for Everybody.

2.1 Lecture on Functions

  1. Duplications
    • Do not repeat yourself!
    • Origins of duplications.
    • Types of duplications:
      • copy-paste or copy-paste-adapt of code,
      • across representations.
    • Strategies of avoiding duplicates.
  2. Functions
    • Characteristics of well-defined functions.
    • Iterative process of writing functions.
  3. Scopes
    • Visibility of variables: built-in, global and local.
    • Lookup rule for variables.
    • Exchanging data between scopes.
    • Returning vs. printing value.
    • Illustrative examples for python tutor.
  4. Functions import
    • Direct and indirect program interpretation.
    • All-inclusive vs. modular solution.
    • Distinction of direct and indirect running of a program.
    • Different options for importing.
  5. Comments
    • Characteristics of good comments.
    • In-code documentation with docstring.

Slides only: raising exceptions.

Books:

  • The Pragmatic Programmer: your journey to mastery by David Thomas, Andrew Hunt
  • Clean Code: A Handbook of Agile Software Craftsmanship by Robert C. Martin
20S198891 U04 functions 01 duplications
duration: 16:30
20S198891 U04 functions 02 functions
duration: 07:56
20S198891 U04 functions 03 scopes
duration: 16:22
20S198801 U04 L05 functions import
duration: 08:31
20S198891 U04 functions 04 comments
duration: 10:11
total duration: 59:30

Slides:

2.2 Exercises on Functions

  • Program / SQFeet’s video is silent on purpose, you should read the description instead of listening
  • Exercises / Reuse is explained in the lecture video
  • Best Practices / Docstring is explained in the lecture video
20S198891 U04 functions 10 demo tasks
duration: 03:02
198801 U06 Functions Programs SqFeet demo
duration: 03:05
total duration: 06:07

Exercises:

  • the material is provided in OLAT