3 ms·
I rather see functions as transformations, in the mathematical sense. A function receives an input and produces an output, according to some logic that only the
by abricq 4y ago
I rather see functions as transformations, in the mathematical sense. A function receives an input and produces an output, according to some logic that only the function is responsible for. A small logical block that can be reused into somehow bigger logical blocks (i.e. programs). I think it is much more realistic, lead you to good programming practice, and also much more fun.
I have tried to teach that and students have always (seem) to like & understand this approach. It was for student at university level, so maybe more able to understand this 'functional' view of functions.
- thanatropism 4y agoYes, but functions in Python are not that. Mathematical transformations don't support closures for one. Dictionaries are more like functions and indeed I taught myself to understand hashmaps as "frozen functions" way back when. You can easily find the set-valued inverse of a function by saying {v: [k for k in d.keys() if k[v]==v] for k, v in d.items()} and that's close to the mathematical definition too.
- xigoi 4y ago> Mathematical transformations don't support closures for one. What? In mathematics, you often have things like “let c be a real number; let f(x) = x + c”.