- Functional Python Programming
- Steven F. Lott
- 221字
- 2021-08-27 19:20:23
Familiar territory
One of the ideas that emerged from the previous list of topics is that most functional programming is already present in Python. Indeed, most functional programming is already a very typical and common part of OOP.
As a very specific example, a fluent Application Program Interface (API) is a very clear example of functional programming. If we take time to create a class with return self() in each method function, we can use it as follows:
some_object.foo().bar().yet_more()
We can just as easily write several closely related functions that work as follows:
yet_more(bar(foo(some_object)))
We've switched the syntax from traditional object-oriented suffix notation to a more functional prefix notation. Python uses both notations freely, often using a prefix version of a special method name. For example, the len() function is generally implemented by the __len__() class special method.
Of course, the implementation of the preceding class might involve a highly stateful object. Even then, a small change in viewpoint may reveal a functional approach that can lead to more succinct or more expressive programming.
The point is not that imperative programming is broken in some way, or that functional programming offers a vastly superior technology. The point is that functional programming leads to a change in viewpoint that can, in many cases, be helpful for designing succinct, expressive programs.
- Hyper-V 2016 Best Practices
- Visual Studio 2012 Cookbook
- CMDB分步構建指南
- 新一代通用視頻編碼H.266/VVC:原理、標準與實現
- 摩登創(chuàng)客:與智能手機和平板電腦共舞
- C語言程序設計
- Java程序設計與計算思維
- TypeScript圖形渲染實戰(zhàn):基于WebGL的3D架構與實現
- Python忍者秘籍
- Java高并發(fā)核心編程(卷1):NIO、Netty、Redis、ZooKeeper
- 軟件測試綜合技術
- Buildbox 2.x Game Development
- Python趣味編程與精彩實例
- SSH框架企業(yè)級應用實戰(zhàn)
- Kotlin進階實戰(zhàn)