4.4.1. Functional programming in Python¶
4.4.1.1. Abstraction for behaviors¶
Object-oriented programming (OOP) is the abstraction for things that have noun attribute. Just like biological classification, scientists use the context Domain, Kingdom, Phylum, Class, Order, Family, and Genus to describe creatures. It is scientifically rigorous, comprehensive, but not such flexible to deal with open set. (for example to describe a totally new specie which can not been interpreted in this system indeed).
Functional programming (FP) is the abstraction for things that have verb attribute. We describe the data without modification raw; we define the process steps for data as preprocessing; we called the behaviors of extracting informative things from data feature engineering; we train to find the pattern possibly underlying the data. No matter what investigation in what field we are struggling, we repeat those behaviors step by step, always.
4.4.1.2. Using functions¶
Like many other programming languages, python is also supports multi-paradigm well. The function can be used as value to pass in, the modified function can be return as a value as well, after which the currying occurs.
Note
The term function currying refers the changes of calling for function with form of f1(a, b, c), into
the form as f2(a)(b)(c). In modern programming, this architecture is helpful to decoupling our operation
logic on data. In the last form, f2(a) return a function that the behavior a is determined; then
f2(a)(b) return the behavior b is determined as well; assume the c is the data, it is
clear that data c can be processed, if and only if the pre-processes a and b are pre
defined.
For building the function with high reusability, here shows some advice:
make arguments concise when parameterization
variable-length arguments will make function easy to be extended
design for call back in where calculation method might vary
for one-time manipulating, use lambda
- Authors:
Chen Zhang
- Version:
0.0.5
- Created on:
Jun 16, 2023